Reputation: 307
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();
}
Upvotes: 2
Views: 2379
Reputation: 391
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>
Upvotes: 1
Reputation: 1345
Try this code
<script>
function nWin() {
var w = window.open();
var html = $("#toNewWindow").html();
$(w.document.body).html(html);
}
$(function() {
$("a#print").click(nWin);
});
</script>
<div id="toNewWindow">
<p>Your content here</p>
</div>
<a href="javascript:;" id="print">Open Window</a>
Upvotes: 1