是否可以扩展使用 window.open 打开的新窗口的 DOM,而无需在新窗口中加载prototypeJS?
是否可以使用如下内容扩展我打开的新窗口的 DOM:
var newWindow = window.open('about:blank', 'testWindow', '');
Element.extend(newWindow);
我认为 Element.extend 会起作用。但我确实在 DOM 中看到了对原型的任何引用。
有什么想法吗?
谢谢你! 莫滕
Is it possible to extend the DOM of a new window that I opened, using something like this:
var newWindow = window.open('about:blank', 'testWindow', '');
Element.extend(newWindow);
I thought Element.extend would work.. But I done see any refference to prototype in the DOM.
Any ideas?
Thank you!
Morten
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么你不想在新窗口中再次加载原型???我的意思是引用在缓存中,所以,如果你再次插入它并不重要......有什么原因吗???
Why you don't want to load prototype again in the new window??? I mean the reference is in cache so, it doesn't matter if you insert it again... is there a reason???
由于跨域安全策略,它可能不适用于
about:blank
。如果新窗口不显示来自同一域的页面,则您无法访问该窗口的 DOM。其次,即使窗口是同源的,你也不能一打开它就访问它的DOM。您需要等待它加载。最简单的方法是让子窗口在加载完成后(在 DOMContentLoad 或 Window.onload 之后)调用父窗口中的函数。或者,您可以在
setTimeout
循环中重复检查 DOM 是否可用(不要使用 while 循环,因为它会挂起浏览器,直到子窗口准备就绪)。一旦 DOM 准备就绪,您就可以用它做您想做的事情。It will probably not work for
about:blank
because of the cross-domain security policy. You can not access the DOM of a new window if that window isn't displaying a page from the same domain.Secondly, even if the window is same origin, you can not access its DOM as soon as you open it. You need to wait for it to load. The easy way is to have the child window call a function in the parent window when it's done loading (after DOMContentLoad or Window.onload). Or you can repeatedly check if the DOM is available in a
setTimeout
loop (do not use a while loop because it hangs the browser till the child window is ready). Once the DOM is ready, you can do what you want to do with it.