Satinder Singh Satinder Singh - 5 days ago 4
HTML Question

how we can open a new browser window for preview of html

I am working on html and jquery . I am trying to open a new window of browser with my html code . I got some information regarding DOM window open method but that method always open a new tab but I want open a new different window . please anyone help me following is w3schools example for reference .

function myFunction() {
var w = window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
}

Answer

You can use below code for open new window

<!DOCTYPE html>
<html>
<body>

<p>Click the button to open a new window called "MsgWindow" with some text.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var myWindow = window.open("", "MsgWindow", "width=200,height=100");
    myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>");
}
</script>

</body>
</html>
Comments