PDA

View Full Version : Use AJAX to check what an iframe's state is


the-dream
01-28-2008, 01:10 PM
Ok...

So I don't really use AJAX / JavaScript very much. I'm more of a PHP kinda guy.

What i am trying to do is check what page an iframe is on using ajax, if it is on http://www.example.com/ then don't do anything but if its on any other page, display some text. I don't know if this is even possible, if it is please enlighten me to how this could be achieved.

Thanks,
~ Christian

A1ien51
01-28-2008, 10:17 PM
Ajax has nothing to do to look at an ifrmae on the current page.

Ajax is about using the XMLHttpRequest object.

If the iframe is on the current page you access it by its id


var ifr = document.getElementById("iframeId");


you can than look at the location object


alert(ifr.location.href);


Now here is the catch, if the iframe is in a different domain, you can not touch it. That is a securiyt violation so there is nothing you can do.

Eric