call href click on document.ready
a have two aspx pages page1.aspx and page2.aspx.
i have anhref
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();
});
精彩评论