如何使用Javascript将内容写入其他浏览器窗口? [英] How do I write content to another browser window using Javascript?

查看:106
本文介绍了如何使用Javascript将内容写入其他浏览器窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用window.open()打开了一个新窗口,我想使用window.open()调用的引用,然后将内容写入新窗口。我试过通过使用myWindow.document.body.innerHTML = oldWindowDiv.innerHTML将旧的窗口复制到新的窗口;但这不行。任何想法?

I've opened a new window with window.open() and I want to use the reference from the window.open() call to then write content to the new window. I've tried copying HTML from the old window to the new window by using myWindow.document.body.innerHTML = oldWindowDiv.innerHTML; but that's doesn't work. Any ideas?

推荐答案

window.open()是到子窗口的窗口对象。所以你可以做任何你通常会做的,这里是一个例子:

The reference returned by window.open() is to the child window's window object. So you can do anything you would normally do, here's an example:

var myWindow = window.open('...')
myWindow.document.getElementById('foo').style.backgroundColor = 'red'

请记住,只有父窗口具有相同的域,这将只起作用。否则跨网站脚本安全限制将阻止您。

Bear in mind that this will only work if the parent and child windows have the same domain. Otherwise cross-site scripting security restrictions will stop you.

这篇关于如何使用Javascript将内容写入其他浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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