Closed Thread Icon

Topic awaiting preservation: Crossdomain javascript... Pages that link to <a href="https://ozoneasylum.com/backlink?for=8822" title="Pages that link to Topic awaiting preservation: Crossdomain javascript..." rel="nofollow" >Topic awaiting preservation: Crossdomain javascript...\

 
Author Thread
Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 08-20-2003 17:25

Hi,

The scenario is, you have an inline frame, and its onload calls a javascript function. Everytime someone navigates in the page, I do things like get the title, get the height, etc. However, if they navigate away from my domain in the frame, then this will produce javascript error messages. My question is, is there any way to determine if the frame is in my domain or not? Preferably without js errors. I mean, maybe there is error handling, or something that can be used to hide the error messages, or there is a boolean, I don't know.

Thanks,
Hub-izer

MajorFracas
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2003

posted posted 08-20-2003 22:27

You could test for the existance of something inside the iframe (e.g. the inner document) inside try/catch blocks. If your test fails (due to permission errors) you can catch the exception and know that the document inside the iframe is outside your domain.

Try something like this:

code:
function isInDomain() {
var returnVal = false;
try {
frame = document.getElementById('idOfYourIframe');
if (frame.contentDocument &#0124; &#0124; frame.contentWindow.document) {
returnVal = true;
}
}
catch (e) {
returnVal = false;
}
finally {
return returnVal;
}
}



Note that IE uses contentWindow, Opera uses contentDocument and Netscape uses either...

Cheers!

Hub-izer
Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 08-21-2003 09:07

AHA! There is try/catch in Javascript!! WOOHOO!
You have just done me an unimaginably large favor, you have literally opened up worlds before me! Thank you!

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 08-21-2003 09:16

Yes, at least from JavaScript 1.5 there is "try catch".
Take a look here: http://www.devshed.com/Client_Side/JavaScript/JavaScript_Exception/page1.html
For more info.
/DAn

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

« BackwardsOnwards »

Show Forum Drop Down Menu