简体   繁体   中英

cross-domain iframe realtime url detect

I want create a web page like www.domain.com/iframe that load a cross-domain website on it like yahoo.com. visitor want browse on iframe page (yahoo.com) and my main page must always detect iframe url.

Because ross-domain iframe policy its not access it via

document.getElementById('myframe').contentWindow.location.href;

I do some googling on it, ways like jquery PostMessage , porxy ifrmae .... but It not work for me. my iframe is not on my access to add java functions.

I dont have coercion to use iframe, I want a technique to show an other link on my page and know position of that other view on my page to do some things...

please help me in this problem.

With jquery you can do it

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
Links: <br />
<a title="http://validator.w3.org/">w3c.com</a><br />
<a title="http://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal">wiki in french</a><br />

<iframe id="myiframe" src="http://www.google.fr" width="100%" height="100%"></iframe>

 <script>
 $(document).ready(function() {

   $("a").click(function () {
     var $urls = $(this).attr("title");
    $("#myiframe").attr("src", $urls);
     return false;
  });
});
 </script>

.attr() will change the src="" of your iframe. Now you can just interact the attr with an event like on click or whatever you want.

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