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

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

问题描述

我用 window.open() 打开了一个新窗口,我想使用 window.open() 调用中的引用,然后将内容写入新窗口.我尝试使用 myWindow.document.body.innerHTML = oldWindowDiv.innerHTML; 将 HTML 从旧窗口复制到新窗口;但这不起作用.有什么想法吗?

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() 返回的引用是对子窗口的 window 对象.所以你可以做任何你通常会做的事情,这是一个例子:

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天全站免登陆