Search code examples
javascriptbrowserwindow.open

How to open a new window or tab and feed it javascript to execute?


I made a game, and I want it to give the map data that is all stored in a map array. I know how to get javascript to print an object or array to the body so it's copy/pastable javascript.

I want to open a new window or tab to show the map data in when you press a button.

Here's what I have for the map loader, then it prints it to the document. http://jsfiddle.net/Tgwizman/Cx2eF/

I simply want it to show this in a new window or tab without having to make a new page.


Solution

  • One way to do this: (make sure pop-ups are enabled)

    It automatically opens a new window. I'll let you figure out the button-pressing part.

    http://jsfiddle.net/Cx2eF/3/

    sampleWindow = window.open("", "myWindow", "location=no,menubar=yes,resizable=yes,scrollbars=yes,height=640,width=800");
    sampleWindow.document.writeln(mapExport);
    sampleWindow.document.close();
    ​