Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access iFrame URL with JQuery / Javascript

I have a page like this...

<div>
<iframe id="mainContent">
<iframe id="littleBox">
</div>

and I want to do this...

 $(".someButton").live('click', function() {
       alert(/*The URL That the Main Frame is ON*/);
 });

I found this: $("#mainFrame").get(0).location.href, but it doesnt work...

Also, I need it to return the current url, so if someone navigates around it should return the current page they are on.

like image 636
Jason Avatar asked Dec 05 '25 15:12

Jason


1 Answers

Okay so you mean you have to access the URL of the parent from the child iframe?

$("#mainFrame").get(0).contentWindow.location
like image 180
xar Avatar answered Dec 07 '25 16:12

xar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!