javascript - How can I create a new window object without iframes? - Stack Overflow

How can I make a new Window object, myWindow, that is independent to window (so modifying e.g. myWindow

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
Add a ment  | 

2 Answers 2

Reset to default 3

Emm... 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();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744759746a4592103.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信