开发者

Top or parent in JavaScript is undefined in SharePoint 2010 using FireFox or Opera

开发者 https://www.devze.com 2023-04-05 17:24 出处:网络
I\'m trying to access the URL of a SharePoint page from within an iframe. It workes fine in IE 9. But not in Firefox or Opera. If I move the script into a common ASP.NET application it works in all br

I'm trying to access the URL of a SharePoint page from within an iframe. It workes fine in IE 9. But not in Firefox or Opera. If I move the script into a common ASP.NET application it works in all browsers.

What is happening in SharePoint when it comes to top and parent?

I have tried with top.location.href, but the problem persists.

This is my JavaScript code:

  try {
    var url = parent.location.href;
    alert(url);
    var index = url.indexOf('SitePages开发者_如何学编程');
    if (index) {
      alert(index);
      url = url.substring(0, index);
      alert(url);
    }

    alert('done');
  }
  catch (ex) {
    alert(ex.Message);
  }


You're experiencing the cross-domain (aka cross-origin) scripting restrictions. If you're the maintainer of the server, the documentation about the Access-Control-Allow-Origin: * header may interest you. This response header should be sent along with your framed web page in order to unlock the ability to script across domains.

0

精彩评论

暂无评论...
验证码 换一张
取 消