Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add content to a new open window

I don't know how to solve this issue, I've trying reading many post but no one answer to it.

I need to open a new window with a page already coded (inside the same domain) and add some content.

The problem is that if I use OpenWindow.write() the page is not loaded yet or it overrides everything and only the code added through write appears.

var OpenWindow = window.open('mypage.html','_blank','width=335,height=330,resizable=1'); OpenWindow.document.write(output); 

output is the code I need to append.

I need it to work at least on Firefox, IE and GC.

Thanks in advance. It is not a problem if I need to use JQuery.

like image 434
Mario Corchero Avatar asked May 06 '12 18:05

Mario Corchero


People also ask

How do I open this content in a new window?

Using Right Click. Right click on the link on your current window. Choose Open in New Window . The page will open in a new window.

How do I open a new window in the same browser?

To open a new window, use a keyboard shortcut: Windows & Linux: Ctrl + n. Mac: ⌘ + n.


1 Answers

When You want to open new tab/window (depends on Your browser configuration defaults):

output = 'Hello, World!'; window.open().document.write(output); 

When output is an Object and You want get JSON, for example (also can generate any type of document, even image encoded in Base64)

output = ({a:1,b:'2'}); window.open('data:application/json;' + (window.btoa?'base64,'+btoa(JSON.stringify(output)):JSON.stringify(output))); 

Update

Google Chrome (60.0.3112.90) block this code:

Not allowed to navigate top frame to data URL: data:application/json;base64,eyJhIjoxLCJiIjoiMiJ9

When You want to append some data to existing page

output = '<h1>Hello, World!</h1>'; window.open('output.html').document.body.innerHTML += output;  output = 'Hello, World!'; window.open('about:blank').document.body.innerText += output; 
like image 81
iegik Avatar answered Sep 19 '22 23:09

iegik