Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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 如何跨域访问另一个页面元素_Javascript_Html - Fatal编程技术网

Javascript 如何跨域访问另一个页面元素

Javascript 如何跨域访问另一个页面元素,javascript,html,Javascript,Html,我有一个html页面,我想从中加载子html并获取跨域的元素数据。访问此内容的方式有哪些 我无法在此处修改child.html http://localhost:8080/child.html <html> <body> <div id="test">Send me a message!</div> </body> </html> http://localhost:8080/chil

我有一个html页面,我想从中加载子html并获取跨域的元素数据。访问此内容的方式有哪些

我无法在此处修改child.html

http://localhost:8080/child.html
<html>    
    <body>
        <div id="test">Send me a message!</div>
    </body>
</html>
http://localhost:8080/child.html
给我留言!
main.html

<html>
    <load child html>
    <body>
        <script> How to access element "test" here.
    </body>
</html>

如何在此处访问元素“test”。
我的问题:

  • 访问跨域页面元素ID的好方法是什么
  • 我听说我们可以用。。但我无法从child.html发布消息

  • 使用一个接受json数据类型的ajax调用。如果您要跨域,如果您尝试作为ajax请求加载,则会遇到限制。除非你能控制源服务器,否则这不是一个好办法。你能从两个域访问/控制这两个页面吗?我可以修改main.html页面,但我不能控制child.html。但我需要访问child元素。html@NilotpalBarpujari如果是ajax调用,我还需要在child.html中添加js。但我无法控制child.html