简体   繁体   中英

Masked domain and cross domain javascript

So, I have a website fabtab.org and all it has is an iframe which embeds my actual website in it which is at fab.org.org/fabtab (I have this setup as fabtab.org is hosted with some website provider, and I host my website from home at fab.org.org so the provider simply masks my URL and forwards requests to my website at home)

now on fab.org.org/fabtab i have a frame set so the top frame has the title/navigation for the website and the bottom frame has the website contents.

What I would like to do is have a close button in the top frame that causes the browser URL to go to the URL that is specified by the bottom frame URL

I have done this in javascript like so:

function GotoBodyURL()
{
//debugger;
    var parentDocument = parent.document;
    var bodyDocument = parentDocument.getElementById('content');
    parent.window.location.href = bodyDocument.location;
}

so this code runs when you click close on the top frame. This works when my website is accessed from fab.org.org/fabtab, but when it is run from fabtab.org I get cross domain javascript errors. So what I have been trying to do, unsuccessfully, is set the document.domain = "fab.org.org"

this is the error chrome gives me:

Unsafe JavaScript attempt to access frame with URL http://fabtab.org/ from frame with URL http://fab.org.org/fabtab/games/head/show_close=False . Domains, protocols and ports must match.

if my top frame calls parent.document, shouldnt that be the document that has my frameset which is the same domain so there should be no cross domain javascript? OR is the actual problem that the browser see's my website trying to access fab.org.org inside of fabtab.org and simply wont allow it? If this is the case, will modifying the iframe at fabtab.org to have the domain set to fab.org.org in javascript do the trick?

我已经通过在我的网站上使用CNAME条目解决了问题,而不是使用带有屏蔽的转发

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM