I am trying to open a new window from javascript but nothing is being inserted into the html:
var callScriptText = $('#callScriptText').html(); var url = '/Action/CallScript/?callScript='; // Open the current call script in a new window var openWindow = window.open(url, 'callScriptPopup', 'width = 500, height = 500'); $(openWindow).html(callScriptText);
Does anyone know why?
You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.
To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method. Firstly, add the web page you want to add.
Here's an example to open a new window with content using jQuery
<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</a>
EDIT: For those who say that this code doesn't work, here's a jsfiddle to try it http://jsfiddle.net/8dXvt/
Try this:
var x=window.open(); x.document.open(); x.document.write('content'); x.document.close();
I find it works in Chrome and IE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With