Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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_Cross Domain_Xss - Fatal编程技术网

Javascript 从外部脚本访问外部脚本的位置对象

Javascript 从外部脚本访问外部脚本的位置对象,javascript,cross-domain,xss,Javascript,Cross Domain,Xss,这里有一个有趣的JS q。。。假设你有: host1.com上的host1.html,它引用了host2.com上的外部javascript(host2.js)。在host2.js中,我想获取为host2.js提供服务的主机的location.hostname,但由于host2.js是在host1.html中调用的,因此它返回host1的location.hostname 有没有办法在调用的外部脚本中获取外部脚本的location对象?我想以前也有人问过类似的问题,答案总是否定的,这是不可能的

这里有一个有趣的JS q。。。假设你有:

host1.com上的host1.html,它引用了host2.com上的外部javascript(host2.js)。在host2.js中,我想获取为host2.js提供服务的主机的location.hostname,但由于host2.js是在host1.html中调用的,因此它返回host1的location.hostname


有没有办法在调用的外部脚本中获取外部脚本的location对象?

我想以前也有人问过类似的问题,答案总是否定的,这是不可能的

解决办法:

  • 通过父文档的
    脚本
    元素,使用计数器变量,找出我们所处的位置(ugh)


  • 将当前URL输出到服务器端包含的脚本中,例如在PHP中:
    script\u current\u URL=我想以前也有人问过类似的问题,答案总是否定的,这是不可能的

    解决办法:

    • 通过父文档的
      脚本
      元素,使用计数器变量,找出我们所处的位置(ugh)

    • 将当前URL输出到服务器端包含的脚本中,例如在PHP中:
      script\u current\u URL=
      
       <script type="text/javascript">
       script_current_url = "http://www.example.com/include.js";
       </script>
      
       <script type="text/javascript" src="http://www.example.com/include.js">
       </script>