Leandro Bardelli
Leandro Bardelli

Reputation: 11578

How can I get the url of an iframe?

How can I get the URL of an iframe that load a page in other site (CORS)?

iFrameObject.contentWindow.location.href 

returns CORS Error

UPDATE:

The user will navigate inside the iframe and will get another url that I didn't know. This is what I want to check, if the user gets to that url, the iframe close itself.

Related question: How to get data from an external site inside a cordova application? (I'm trying to get the information in the paramters of the url)

Upvotes: 2

Views: 300

Answers (1)

Marco Bonelli
Marco Bonelli

Reputation: 69346

You can simply get it's src property:

var URL = iFrameObject.src;
// something like "http://example.com"

UPDATE: Since that the URL of the frame will change and become different from the src property, you'll not be able to access it without violating the Cross-Origin policy. You cannot perform any action in an iframe that has got another origin.

Upvotes: 2

Related Questions