使用Javascript在弹出网页上单击x按钮时如何处理?
我在插件中有一个继承自 System.Web.UI.Page 的“弹出”网页,该插件是大型 Web 框架的一部分。标记位于下面的
内。当用户单击“关闭”按钮(id = _close)以及用户单击页面右上角的“x”按钮时,我需要执行一些操作(更新后面的页面)。我的页面未显示在浏览器中。我让“onclick”(在后面的代码中)适用于下面的“关闭”按钮,但我不知道如何检测何时单击“x”按钮。我尝试了 window.beforeunload
和 window.onclose
,它不起作用。当我打开网页并单击“关闭”(_close
) 按钮时,会弹出“Hello World”。 当单击“_close”按钮时,如何以相同的方式处理“x”上的单击?
<script language="javascript">
function doClose() { alert('Hello World!'); } window.onload = doClose(); // also tried with window.beforeunload </script>
I have a “pop-up” web page inherits from System.Web.UI.Page in a plug-in which is a part of a large web framework. The markup is inside <asp:Content>
below. I need to perform some actions (updating the page behind) when the user clicks on “Close” button (id = _close) and when the user clicks on the ‘x’ button on the right corner of the page. My page is not displayed in the browser. I got the “onclick” (in the code behind) to work for “Close” button below, but I don’t know how to detect when the ‘x’ button is clicked. I tried on window.beforeunload
and window.onclose
, it doesn’t work. “Hello World” pops up when my web page opens and when I click “Close” (_close
) button.
How do I handle for the click on the ‘x’ the same way when “_close” button is clicked?
<script language="javascript">
function doClose() { alert('Hello World!'); } window.onload = doClose(); // also tried with window.beforeunload </script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在开启器上执行代码。在opener中编写一个方法并从弹出窗口中执行它。
http://www.w3schools.com/jsref/prop_win_opener.asp
You can execute the code on the opener. Write a method in opener and execute it from the pop-up window.
http://www.w3schools.com/jsref/prop_win_opener.asp