使用JQuery访问新窗口的DOM [英] Using JQuery to Access a New Window's DOM

查看:80
本文介绍了使用JQuery访问新窗口的DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个新窗口,其中包含用户将要打印的文本. 我想做类似的事情:

I am creating a new window that will contain text that user will print. I would like to do something similar to this:

var new_win = window.open();
$(new_win.document).html("Test");

推荐答案

在这种情况下,您尝试访问没有jQuery增强功能的dom.您需要首先将jquery.js加载到此文档中.如果完成,语法将是这样.

In this case you are trying to access a dom wich has no jQuery enhancement. You need to first load a jquery.js into this document. If done the syntax would be.

var popup = window.open('/some/url.html');
popup.document.$('body').html('test');

但是要非常小心,在多文档管理和通信中,许多不同的浏览器版本和供应商之间存在许多错误和不便之处.

But be very careful, in multi document management and communication are many bugs and inconveniences between the many different browser versions and vendors.

如果将通信保持在绝对最低限度,然后将另一个完整的html文件加载到弹出窗口中,那确实会更好.

It would really be better if you keep communication to a absolute minimum, and just load another complete html file into the popup.

这篇关于使用JQuery访问新窗口的DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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