开发者

call href click on document.ready

开发者 https://www.devze.com 2023-02-17 05:02 出处:网络
a have two aspx pages page1.aspx and page2.aspx. i have an href in page1.aspx<a id=\"GoHref\" href=\"page2.aspx\">

a have two aspx pages page1.aspx and page2.aspx.

i have an href in page1.aspx <a id="GoHref" href="page2.aspx">

i want that when users click docHref to be redirected to page2.aspx and download a doc file via an automatic click on <a id="DocHref" runat="server">

page2.load is as below:

       protected void Page_Load(object sender, EventArgs e)
    {

       if(!IsPostBack)
            DocHref.HRef="./mydoc.doc";
    } 
开发者_如何学C

i 'd like to do do an automatic click on document.ready, something like this:

     $(document).ready(function() {

         $('#DocHref').trigger('click');

    });

But it doesn't work !!

is this a good way to download a doc file ? Or there a better server side way?

Thanks in advance.


You're better off using the window .location property than simulating clicks as there is far less overhead.

<a id="myLink" href="somewebsite.com">My Link</a>

$(function() {
   window.location.href = $("#myLink").attr("href");
});


Lets say you have html like so:

<a id="myLink" href="somewebsite.com">My Link</a>

To have jQuery simulate a click:

$(function() {
  $("#myLink").click();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号