开发者

Opening a new browser window with specificed HTML

开发者 https://www.devze.com 2023-01-30 01:54 出处:网络
I have a webpage which dynamically creates markup within itself. On the click of a certain button I want a client-side event to \'copy\' this markup and place it in the <body> of a blank page wh

I have a webpage which dynamically creates markup within itself. On the click of a certain button I want a client-side event to 'copy' this markup and place it in the <body> of a blank page which it will open in a new browser window. Is there 开发者_运维问答any way to do this?


As you want it on the client-side using JavaScript (from your tags), you can use the window.open.

var w = window.open("", "Some Title");
w.document.body.innerHTML = "yay!";

Note that, in this example, the target inside window.open function is a blank string which means that the new window opened will be a blank window (not redirected to any URL like your website's).


When opening a new window, the function returns a "handle" to this window.

You can then manipulate the new window with javascript (so long as it points to a URL on the same domain).

var newWindow = window.open ("", "mywindow", "location=1,status=1,scrollbars=1,width=100,height=100");
newWindow.document.write("Hello world");

The newWindow.document gives you access to the DOM of the new window.

0

精彩评论

暂无评论...
验证码 换一张
取 消