tags:

views:

4257

answers:

4

This jQuery will return the source URL of a frame:

$('#frame-name').attr('src')

But if a link inside the frame is clicked, the original source is still returned.

Is it possible to detect the new source URL? Or get the source of the new document loaded in the frame? If either of those is a yes, are there security constraints if the source frame contains an URL from a different domain?

A: 

AFAIK there is no good way to do this with jQuery. You need to use location.href on the html element so if you get the element with jQuery you could do this.

$("#iframe-name").get(0).location.href
Adam Peck
$("#iframe-name").get(0).location.href is undefined
chipotle_warrior
Are you doing this from the parent frame?See if the selector is actually returning an HTMLElement.alert($("#iframe-name").get(0));
Adam Peck
+1  A: 

Is the link from a different domain? Browsers may restrict access to any information about what a user has open in other windows or frames if it's on another site as a security precaution.

ʞɔıu
A: 
parent.frames[1].location.href;

Not jQuery, but what I was looking for. However, kicks a security error if the source is on a different domain.

chipotle_warrior
A: 

As a browser extension, security errors would go away.

For example, Greasemonkey is a Firefox extension where you can explore, and if you like the script you create, it can be packaged up into its own extension, I believe.

Alternatively, you can inject script into a page as a bookmarklet.

larham1