Access parent URL from iframe

后端 未结 16 1267
野性不改
野性不改 2020-11-22 10:00

Okay, I have a page on and on this page I have an iframe. What I need to do is on the iframe page, find out what the URL of the main page is.

I have searched aroun

16条回答
  •  有刺的猬
    2020-11-22 10:23

    I couldnt get previous solution to work but I found out that if I set the iframe scr with for example http:otherdomain.com/page.htm?from=thisdomain.com/thisfolder then I could, in the iframe extract thisdomain.com/thisfolder by using following javascript:

    var myString = document.location.toString();
    var mySplitResult = myString.split("=");
    fromString = mySplitResult[1];
    

提交回复
热议问题