dqwd71332 2016-03-21 18:56
浏览 142
已采纳

从另一个站点远程调用javascript函数

I have a upload script in another host and after remote file upload with Ajax I call a function like this :

echo '<script language="javascript" type="text/javascript">window.top.window.stopUpload('.$result.' , \'res2\' , uploaded , dkey);</script>';

the stopUpload function in the main page should run and do some thing (show pictures and ...) but I get Permission denied error

Error: Permission denied to access property "stopUpload"

tip : Imagine I have stopUpload function in pageA and I call send file with ajax to upload in my another Host page called pageB I have a stopUpload function in pageB which should run on pageA after upload complete but face to above error ...

Can I call javascript function in another page remotely?

Thanks.

  • 写回答

1条回答 默认 最新

  • duanliaoyu8419 2016-03-21 19:06
    关注

    You are probably violating Same Origin Policy.

    An Iframe can access parent window content only if they both belong to same origin. An origin consists of Protocol (http/https), domain name(example.com and port(default 80). If any of these are different then sites are considered from different origins. If you are able to modify content of both the sites then you can manually set the document.domain=domain.com. After that you won't get the error.

    #Edit

    Both the sites should at least have super domain in common for manual domain setting to work.

    For example, facebook.com and google.com can never be compatible since their super domains are different.

    However docs.google.com and developer.google.com can be compatible as they have super domain google.com in common.

    They both would have to declare document.domain=google.com in a script tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。