admin管理员组文章数量:1391987
How can I make a new Window
object, myWindow
, that is independent to window
(so modifying e.g. myWindow.Array.prototype
does not effect window.Array.prototype
), without creating an <iframe>
?
At the moment I'm doing it as follows
function newWindow(){
var myFrame = document.createElement('iframe'), myWindow = undefined;
myFrame.style.display = 'none';
myFrame.src = 'javascript:undefined;';
document.body.appendChild(myFrame);
myWindow = myFrame.contentWindow;
document.body.removeChild(myFrame);
return myWindow;
}
Ultimately, I'd like to make my own copies of core object types and prototype them.
How can I make a new Window
object, myWindow
, that is independent to window
(so modifying e.g. myWindow.Array.prototype
does not effect window.Array.prototype
), without creating an <iframe>
?
At the moment I'm doing it as follows
function newWindow(){
var myFrame = document.createElement('iframe'), myWindow = undefined;
myFrame.style.display = 'none';
myFrame.src = 'javascript:undefined;';
document.body.appendChild(myFrame);
myWindow = myFrame.contentWindow;
document.body.removeChild(myFrame);
return myWindow;
}
Ultimately, I'd like to make my own copies of core object types and prototype them.
Share Improve this question asked Sep 14, 2012 at 0:09 Paul S.Paul S. 66.4k9 gold badges128 silver badges143 bronze badges 1- Related article: How ECMAScript 5 still does not allow to subclass array – Oriol Commented May 4, 2014 at 17:23
2 Answers
Reset to default 3Emm... you can't do that. Well... you may call window.open
, but it will open a new window. And... why do you need that at all? It looks like you are on wrong way.
Depending on what you are doing, a better approach may be to create a normal array, then augment that one particular array instance with the features you need.
function augmentArray(a) {
a.purgeAll = function() {a.length = 0;};
}
var myList = [1, 2, 3];
augmentArray(myList);
myList.purgeAll();
本文标签: javascriptHow can I create a new window object without iframesStack Overflow
版权声明:本文标题:javascript - How can I create a new window object without iframes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744759745a2623684.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论