如何获得不同的窗口';使用javascript创建html
我想使用url打开一个新窗口,获取它的html作为字符串,并将其显示在原始窗口的控制台中 从那时起,我试着:如何获得不同的窗口';使用javascript创建html,javascript,jquery,html,Javascript,Jquery,Html,我想使用url打开一个新窗口,获取它的html作为字符串,并将其显示在原始窗口的控制台中 从那时起,我试着: console.log('response', url) var popup = window.open(url, '_blank', 'width=500,height=500'); popup.onload = function() { setTimeout(function(){ console.log( 'hi',popup.document.documentE
console.log('response', url)
var popup = window.open(url, '_blank', 'width=500,height=500');
popup.onload = function() {
setTimeout(function(){ console.log( 'hi',popup.document.documentElement.outerHTML) }, 2000);
}
弹出窗口已创建,但在原始窗口的控制台中看不到弹出窗口的html
我做错了什么?如果它不在同一个域上,我很确定这是不可能的,因为使用iframe: 但是,如果您拥有这两个页面,您应该能够使用您链接到的SO问题的第一个答案中描述的内容() 注意:如果同时控制父源和子源,还可以让子源调用传入的父源上的方法 它是html: 子窗口
// Call when body is loaded
function SendHtmlToParent() {
window.opener.HtmlReceiver(document.outerHTML);
}
家长
function HtmlReceiver(html) {
console.log(html);
}
给定的url是否与启动弹出窗口的域相同?您使用的是哪种浏览器?url是,我使用的是Firefox如果您尝试处理链接到的问题,并将url更改为stackoverflow.com,您将看到它不起作用。