0

Just wondering if anybody had any ideas on getting an iFrame's URL using possibly jQuery.

For example, if I have an iFrame on my page and somebody is scrolling through the website inside that iFrame is there a lightweight way of grabbing the current URL they are on.

Conceptual
  • 57
  • 2
  • 12

3 Answers3

6

You should be able to do something like

$("#parent").get(0).contentWindow.location
abritez
  • 2,616
  • 3
  • 29
  • 36
1

If someone has to ask it again. I got to make it get src using jquery and rewrite it again as I want to redraw/alter contents that has embeds. It is just, you need to pre-contain the iframe to let you have a direct selector.

var iframeSrc = $('.article-content iframe:first-child').attr('src');
console.log(iframeSrc);

Let me know if this might help.

Cris
  • 21
  • 1
0

use this

 var iframe = '<iframe src="http://someaddress.com" width="600" height="500"></iframe>';

 regEx = /(src)=["']([^"']*)["']/gi;

iframe.replace(regEx, function(all, type, value) {
alert(value); 
});

have a look http://jsfiddle.net/D8gLN/

Manish Jangir
  • 505
  • 3
  • 9
  • 2
    Unfortunately this won't work if the iframe is actually in use and the user navigates inside it (which was the question). – JJJ May 17 '13 at 13:39