0

I want to retrive the url of an external iframe.

The url I can see in my browser, but how can I get the url of that what can I see in the browser via JS or PHP?

  • Preview Image 1 : enter image description here

  • Preview Image 2 : enter image description here

After I click the blue hovered firefox menu item in Preview Image 1, I get the results that I want in firefox.

How to obtain this in JS?

Jesse
  • 8,605
  • 7
  • 47
  • 57

2 Answers2

0

In javascript: Look for the src of the iframe, which is in the HTML code. You could get the iframe by id or by tag, and then get the src property of it.

chtenb
  • 14,924
  • 14
  • 78
  • 116
0

you can do this via javascript.

var url = document.getElementById("myiframe").src;

where myiframe is the ID attribute of your iframe.

trying to do this in php would require you to parse the dom.

this this working here

UPDATE

You can use jquery for this

var url = $('#myiframe').contents().get(0).location.href;

alse you will have to identify browser specific documentWindow object to get the .location.href value.

This issue is explained here.

Community
  • 1
  • 1
Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
  • i have cheked this its working, right. In my case the problem is that the url will redirect the user so it only grabs the url that i have entered at my html code. The main idea behind this was to get the end url where the website has redirected me – Marco Siegfried May 11 '13 at 10:18
  • This solution only works if your target browsers are not using "anti.-cross-origin" policy. – jave.web Aug 03 '15 at 18:53