Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  149] [ 3]  / answers: 1 / hits: 167733  / 13 Years ago, wed, february 22, 2012, 12:00:00

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?


More From » jquery

 Answers
53

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/


[#87292] Tuesday, February 21, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cayden

Total Points: 314
Total Questions: 107
Total Answers: 101

Location: Slovenia
Member since Wed, Apr 6, 2022
2 Years ago
;