将弹出窗口的来源保存为字符串? [英] Save source of popup window as string?
问题描述
有没有办法将一个弹出窗口的源保存为我的域之外的字符串,由以下方式打开:
Is there a way to save the source of a popup window outside of my domain as a string, opened by:
window.open('html');
另一种解决问题的方法是将弹出窗口的输出转换为字符串。我可以使用chrome的 view-source:
浏览器功能并进行弹出:
Also another way of fixing my problem would be directing the output of the popup into a string. I could use chrome's view-source:
browser function and make the popup:
window.open('view-source:html');
因为我只是将它用于个人用途,所以它只能与Chrome兼容,如果这是唯一的方法
Since I am only using this for personal use it can be only compatible with Chrome if that's the only way to do it.
推荐答案
我会建议在弹出窗口中加载要打开的文档,并将其提取为 innerHTML
就像这样:
I would suggest to load the document you want to open in the popup and extract it's innerHTML
like this:
var popup = window.open('http://url.com');
// documentElement is the <html> element so you would get everything inside
var source = popup.document.documentElement.innerHTML;
这适用于IE。我不确定Chrome对跨域弹出窗口的限制,因此您可能需要检查您的本地设置。
This works on IE. I am not exactly sure what Chrome's restrictions for cross-domain popups is so you may have to check your local settings for that.
这篇关于将弹出窗口的来源保存为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!