N
Nathan Sokalski
I want to trigger a download using the onmouseover event. If I open the
browser window using the onmouseover or onclick event and window.open
method, it shows the Open/Save/Cancel dialog like I would expect and want.
However, when I click Open or Save when it was opened using onclick, it asks
you where to save the file and downloads as expected, but if it was opened
using onmouseover clicking Open or Save just closes the dialog, and does not
do the download. Here is a page that I used to test this:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="downloadtester.aspx.vb" Inherits="FileManageTest.downloadtester"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Download Tester</title>
</head>
<body id="BodyTag" runat="server">
<form id="form1" runat="server">
<asp:Label ID="lblClick" runat="server" Text="click"
Font-Bold="true" Font-Size="Large"/><br/>
<div id="div1"
style="background-color:Teal;width:300px;height:300px;"></div><br/><br/><br/>
<asp:Label ID="lblMouseOver" runat="server" Text="mouseover"
Font-Bold="true" Font-Size="Large"/><br/>
<div id="div2"
style="background-color:Green;width:300px;height:300px;"></div>
</form>
</body>
</html>
Partial Public Class downloadtester : Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.BodyTag.Attributes.Add("onclick",
String.Format("if(event.type=='click'&&event.srcElement.id=='div1'){{window.open('downloadfile.aspx?filepath={0}&extension={1}','newwindow');}}",
Server.UrlEncode("C:|config.sys"), Server.UrlEncode(".sys")))
Me.BodyTag.Attributes.Add("onmouseover",
String.Format("if(event.type=='mouseover'&&event.srcElement.id=='div2'){{window.open('downloadfile.aspx?filepath={0}&extension={1}','newwindow');}}",
Server.UrlEncode("C:|config.sys"), Server.UrlEncode(".sys")))
End Sub
End Class
As you can see, the window.open() statements for both the onclick and
onmouseover events are identical, and even though they both ask you if you
want to do the download, only the onclick actually allows you to do it. Why
is this, and what can I do to fix it? The browser that these experiments
were done with is IE7 on Windows Vista. Thank you for any help you can give.
browser window using the onmouseover or onclick event and window.open
method, it shows the Open/Save/Cancel dialog like I would expect and want.
However, when I click Open or Save when it was opened using onclick, it asks
you where to save the file and downloads as expected, but if it was opened
using onmouseover clicking Open or Save just closes the dialog, and does not
do the download. Here is a page that I used to test this:
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="downloadtester.aspx.vb" Inherits="FileManageTest.downloadtester"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Download Tester</title>
</head>
<body id="BodyTag" runat="server">
<form id="form1" runat="server">
<asp:Label ID="lblClick" runat="server" Text="click"
Font-Bold="true" Font-Size="Large"/><br/>
<div id="div1"
style="background-color:Teal;width:300px;height:300px;"></div><br/><br/><br/>
<asp:Label ID="lblMouseOver" runat="server" Text="mouseover"
Font-Bold="true" Font-Size="Large"/><br/>
<div id="div2"
style="background-color:Green;width:300px;height:300px;"></div>
</form>
</body>
</html>
Partial Public Class downloadtester : Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.BodyTag.Attributes.Add("onclick",
String.Format("if(event.type=='click'&&event.srcElement.id=='div1'){{window.open('downloadfile.aspx?filepath={0}&extension={1}','newwindow');}}",
Server.UrlEncode("C:|config.sys"), Server.UrlEncode(".sys")))
Me.BodyTag.Attributes.Add("onmouseover",
String.Format("if(event.type=='mouseover'&&event.srcElement.id=='div2'){{window.open('downloadfile.aspx?filepath={0}&extension={1}','newwindow');}}",
Server.UrlEncode("C:|config.sys"), Server.UrlEncode(".sys")))
End Sub
End Class
As you can see, the window.open() statements for both the onclick and
onmouseover events are identical, and even though they both ask you if you
want to do the download, only the onclick actually allows you to do it. Why
is this, and what can I do to fix it? The browser that these experiments
were done with is IE7 on Windows Vista. Thank you for any help you can give.