我正在尝试从javascript打开一个新窗口,但是没有任何东西被插入到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);
有人知道为什么吗?
发布于 2012-02-23 01:19:02
以下是使用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>
编辑:对于那些说这段代码不能工作的人,这里有一个jsfiddle可以试试http://jsfiddle.net/8dXvt/
发布于 2012-02-23 01:01:50
试试这个:
var x=window.open();
x.document.open();
x.document.write('content');
x.document.close();
我发现它在Chrome和IE上都能用。
发布于 2013-11-13 01:37:05
基于@Emre的答案。
使用javascript,您可以进行链接,所以我将代码修改为:
var x=window.open();
x.document.open().write('content');
x.close();
此外,要将其强制显示为新窗口(而不是新选项卡),请指定第一行的尺寸。但这必须是第三个论点。因此,将第一行更改为:
var x=window.open('','','width=600, height=600');
https://stackoverflow.com/questions/9399354
复制相似问题