javascript - How to detect current iframe url? -


i wrote html code initializes iframe site.

my domain example:

www.mydomain.com/index.html

in there's

 <iframe src = "www.anotherdomain.com/pages/firstpage.html"/> 

i want detect complete new src url whenever iframe gets new one. iframe text consists links other pages within initialised page. possible , legal done ? thanks. appreciated.

i guess goes cross origin issues there work around ?

update

i tried answer

 document.getelementbyid("myiframeid").src 

at frame load event. keeps showing src initialised. not showing updated src.

document.getelementbyid("myiframeid").contentwindow.location.href 

gives security error http frame trying access https in iframe. protocols mismatched.

i made localhost ssl , used https request got blocked. don't know why.

i don't agree answers suggest should use "src" detect current url of iframe. doesn't give current url - url started with.

the domain has same origin use method of following code:

$(document).ready(function() {   $('#myframe').load(function() {     alert($(this).get(0).contentwindow.location.href);   });  }); 

if domains different origins - have access both (or both yours), can use window.postmessage function , contentwindow property of iframe send data parent show when new page loads.

here tutorial on that: http://javascript.info/tutorial/cross-window-messaging-with-postmessage

and if domain in iframe alien, 1 approach can think of load domain in server side script , render data altered links. can call script inside iframe , use contentwindow.location.href property whenever loads.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -