admin管理员组文章数量:1332896
This is the situation. I'm trying to provide a service where someone embedds an iframe on their website with a form in it. At the end when an ajax request es in again I want to pop a new window with a thank you note in it. window.open does not work and my guess is because the window object belongs to the page that embedds it and not the iframe and would then be considered cross-site scripting. Is there another way of doing this?
A thought I had was, that I can create links with target="_new" in my iframe, and clicking that would actually pop another window. Maybe I could create this link and "click"/trigger it with javascript?
I do have control over what the user embedds so potentially I could include a script there too, but the less code there, the better obviously.
Any takes?
This is the situation. I'm trying to provide a service where someone embedds an iframe on their website with a form in it. At the end when an ajax request es in again I want to pop a new window with a thank you note in it. window.open does not work and my guess is because the window object belongs to the page that embedds it and not the iframe and would then be considered cross-site scripting. Is there another way of doing this?
A thought I had was, that I can create links with target="_new" in my iframe, and clicking that would actually pop another window. Maybe I could create this link and "click"/trigger it with javascript?
I do have control over what the user embedds so potentially I could include a script there too, but the less code there, the better obviously.
Any takes?
Share Improve this question asked Mar 15, 2010 at 20:00 miccetmiccet 1,9003 gold badges20 silver badges27 bronze badges 2- 1 You're probably being blocked by a popup blocker. – SLaks Commented Mar 15, 2010 at 20:02
- IIRC the popup is being blocked because it is being triggered from an XHR onreadystatechange event and not from a user triggered event. Browsers are designed to stop popups appearing which are not user triggered. – Quentin Commented Mar 15, 2010 at 20:03
1 Answer
Reset to default 7window.open does not work and my guess is because the window object belongs to the page that embeds it
I don't think so. window
as seen by your script will generally be the window
object of the document inside the iframe
.
More typically, a window.open
on an XMLHttpRequest pletion will be blocked by browsers' built-in pop-up-blockers. They usually only allow new windows to be opened in direct response to user interaction (typically, in the onclick
event handler).
Maybe I could create this link and "click"/trigger it with javascript?
No, otherwise everyone would be doing that to circumvent blockers!
If you're starting an XHR and you know you're going to need a pop-up in the future you'll have to open it now and put some filler content in until the XHR returns, at which point you can update its contents.
本文标签: javascriptOpen window from iframeStack Overflow
版权声明:本文标题:javascript - Open window from iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315818a2451794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论