I would like to make a button on a page that can call a JS function in the same page. The function will need to create (open) new window which its HTML code was given from the JS function itself. How can I do that?
The purpose of this is to produce a print friendly page out of a specific page.
Plea开发者_如何转开发se notice: No AJAX can be used.
var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
function fu() {
var opened = window.open("");
opened.document.write("Your HTML here");
}
<textarea id="code" placeholder="Put code here!" width="500" height="500">
<DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html></textarea>
<input id="width" placeholder="width">
<input id = "height" placeholder="height">
<button onClick="open();">Open the window!</button>
<button onClick="write();">Apply the html to the window</button>
<button onClick = "resize();">Resize the window!</button>
<script>
var win;
function open(){
win = window.open("", "", "");
win.resizeTo(screen.width, screen.height);
}
function resize(){
win.resizeTo(eval(document.getElementById("width")), eval(document.getElementById("height")))
}
function write(){
win.document.write(document.getElementByid("code").value);
}
</script>
Here you can input things and change the window. Hope you enjoy! :)
精彩评论