如何打开一个新窗口,并使用jQuery插入html? [英] How to open a new window and insert html into it using jQuery?

查看:121
本文介绍了如何打开一个新窗口,并使用jQuery插入html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var callScriptText = $我想从javascript打开一个新窗口,但没有任何内容被插入到html中:

( '#callScriptText')的HTML();
var url ='/ Action / CallScript /?callScript =';

//在新窗口中打开当前调用脚本
var openWindow = window.open(url,'callScriptPopup','width = 500,height = 500');
$(openWindow).html(callScriptText);

有谁知道为什么?

解决方案

这里是一个使用jQuery打开一个包含内容的新窗口的例子

 < script> 
函数nWin(){
var w = window.open();
var html = $(#toNewWindow)。html();

$(w.document.body).html(html);

$ b $(功能(){
$(a#print)。click(nWin);
});
< ; /脚本>

< div id =toNewWindow>
< p>您的内容< / p>
< / div>

< a href =javascript :;编辑:
编辑:
编辑:
编辑:
编辑:
对于那些谁说这个代码不起作用,这里是一个jsfiddle来尝试它 http://jsfiddle.net/8dXvt/


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?

解决方案

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/

这篇关于如何打开一个新窗口,并使用jQuery插入html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆