Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 本地获取iFrame内容_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript 本地获取iFrame内容

Javascript 本地获取iFrame内容,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,因此,我一直在试图找出如何从不同的URL获取iFrame的内容源代码。我知道这是不可能的跨域限制,但是,如果html页面是在桌面上运行的呢?就像一个用html构建的本机桌面应用程序一样,这可能吗 var theIframe = document.getElementById("frame"); var theContents = theIframe.contentDocument.body; 源代码将是theIframe.contentDocument.body.outerHTML或.inne

因此,我一直在试图找出如何从不同的URL获取iFrame的内容源代码。我知道这是不可能的跨域限制,但是,如果html页面是在桌面上运行的呢?就像一个用html构建的本机桌面应用程序一样,这可能吗

var theIframe = document.getElementById("frame");
var theContents = theIframe.contentDocument.body;

源代码将是theIframe.contentDocument.body.outerHTML或.innerHTML,这将排除body标记。请求的URL应该在上,也就是说,它也应该是本地文件。因此,如果iFrame加载了外部URL,就无法访问代码了?即使加载iFrame的html在本机桌面应用程序(即localhost?是的)上运行,也无法规避同源策略,无论您在哪里托管应用程序。事实上,一开始我可能有点误解了你的问题,@mbejda删除的答案对于跨来源的案例是完全有效的。好吧,很高兴知道。谢谢