如何在按钮单击时关闭弹出窗口 [英] how to close pop-up window on button click

查看:78
本文介绍了如何在按钮单击时关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗口..在窗口我有一个iframe ..在iframe我有一个按钮..我想关闭弹出窗口,当我点击iframe..plz帮助里面的按钮!!

I have a popup window..In the window i have an iframe..in the iframe i have a button..i want to close the popup window when i click on the button which is inside the iframe..plz help!!

推荐答案

您可以通过从iframe中的文档调用parent.window.close()来完成此操作。有一个要求是无缝的用户和跨浏览器功能:包含iframe的弹出窗口必须已使用javascript命令打开 -



window.open('popup.htm','_ blank','height = 400,width = 400');



如果弹出窗口是用超链接打开的(
You can do this by calling parent.window.close() from the document in the iframe. There is one requirement for this to be seamless to the user and cross-browser capable: The popup window containing the iframe must have been opened with a javascript command --

window.open('popup.htm','_blank','height=400,width=400');

If the popup is opened with a hyperlink (
<a href="popup.htm" target="_blank">More info</a>

)然后close函数无法预测(IE抛出一​​个警告对话框,F irefox默默地忽略它......)



您可以使用两个文件测试代码:popup.htm和iframe.htm。



popup.htm(包含iframe的文档)



) then the close function doesn't work predictably (IE throws a warning dialog, Firefox ignores it silently...)

You can test the code with two files: popup.htm and iframe.htm.

popup.htm (the document containing the iframe)

<html><head><title>iframe closer</title></head>

<script language="javascript" type="text/javascript" >

  function openpopup(){
  
  var popper=window.open('popup.htm','_blank','width=400,height=400');
  popper.focus();
  
  }

</script>

<body>

<iframe src="iframe.htm" width="200" height="200" style="border:solid 1px #990000;"></iframe>


<p onclick="openpopup();" style="color:#ff0000;cursor:pointer;text-decoration:underline;">Open Popup using JavaScript</p>

</body></html></html>





和iframe.htm(iframe中显示的文件:





and iframe.htm (the document displayed in the iframe:

<html><head><title>iframe closer</title>

</head><body>

<p>

  <input type="button" onclick="parent.window.close();" value="Close [x]" />

</p>

</body></html>
</html>





在浏览器中打开popup.htm,单击按钮,您将看到问题。单击红色段落,您可以在javascript打开的弹出窗口中测试close()函数(它将起作用)。



Open popup.htm in your browser, click the button, and you'll see the problem. Click the red paragraph and you can test the close() function on a javascript-opened popup window (it'll work).


这篇关于如何在按钮单击时关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆