0

I have an Ifram and I want to get its current location url when a user click the content.

 <iframe src="http://www.Mysite.com/login.aspx" width="100%" height="800"  id="iframeid" ></iframe>

  <script>
    $(document).ready(function () {
        $("#iframeid").load(function () {
            try{
                alert(this.contentWindow.location.href);// do what you want with this location
            }
            catch (err)
            {
                alert(err.message);
            }
        });
    });
</script>

I use this code but does not return any value.

document.getElementById("iframe_id").get(0).contentWindow.location.url
document.getElementById("iframe_id").contentWindow.location.url
document.getElementById("iframe_id").documentWindow.location.href

I get the error: "Permission denied to access property 'href'"

How to get Current location url?

StarsSky
  • 6,721
  • 6
  • 38
  • 63
Niloo
  • 1,205
  • 5
  • 29
  • 53

0 Answers0