Javascript 打开弹出窗口并禁用父窗口
我想打开一个弹出窗口并禁用父窗口。下面是我正在使用的代码;
function popup()
{
popupWindow = window.open('child_page.html','name','width=200,height=200');
popupWindow.focus();
}
由于某种原因,父窗口不会被禁用。我需要一些额外的代码还是什么情况?
再次,我正在寻找与使用 showModalDialog() 时得到的类似的东西..即它根本不允许选择父窗口..唯一的事情是我想使用 window.open 完成同样的事情
也请建议跨浏览器兼容的代码..
I want to open a popup window and disable the parent window. Below is the code that I am using;
function popup()
{
popupWindow = window.open('child_page.html','name','width=200,height=200');
popupWindow.focus();
}
For some reason, the parent window does not get disabled. Do I need some additional code OR what is the case?
Again, I am looking for something similar to what we get when we use showModalDialog()..i.e. it does not allow to select parent window at all..Only thing is I want to get the same thing done using window.open
Also please suggest the code which will be cross-browser compatible..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
然后在父窗口的body标签中声明这些函数
正如您所要求的,这里是父窗口的完整html代码
new.jsp的内容如下
and then declare these functions in the body tag of parent window
As you requested here is the complete html code of the parent window
Content of new.jsp below
据我所知,您无法禁用浏览器窗口。
您可以做的是创建一个 jQuery (或类似类型的)弹出窗口,当此弹出窗口出现时,您的父浏览器将被禁用。
在弹出窗口中打开您的子页面。
To my knowledge, you cannot disable the browser window.
What you can do is create a jQuery (or a similar kind of ) popup and when this popup appears your parent browser will be disabled.
Open your child page in popup.
这就是我最终做到的!您可以在身体上放置一层(全尺寸),具有高 z-index,当然是隐藏的。当窗口打开时,您将使其可见,使其集中在父窗口(图层)上的单击上,最后在打开的窗口关闭或提交或其他任何情况下将其消失。
主体中的图层:
打开弹出窗口的函数:
保持新窗口聚焦:
在打开的窗口中:
我希望它会有所帮助:-)
This is how I finally did it! You can put a layer (full sized) over your body with high z-index and, of course hidden. You will make it visible when the window is open, make it focused on click over parent window (the layer), and finally will disappear it when the opened window is closed or submitted or whatever.
and layer in the body:
function that opens the popup window:
keeping new window focused:
and in the opened window:
I hope it would help :-)
关键术语是模态对话框。
因此,没有提供内置的模式对话框。
但是您可以使用许多其他可用的,例如这个
The key term is modal-dialog.
As such there is no built in modal-dialog offered.
But you can use many others available e.g. this
您好,@anu 发布的答案是正确的,但它不会完全按要求工作。通过对 child_open() 函数进行轻微更改,它可以正常工作。
Hi the answer that @anu posted is right, but it wont completely work as required. By making a slight change to child_open() function it works properly.