Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I catch exceptions in JavaScript ?

Status
Not open for further replies.

MD

Programmer
Oct 19, 1999
4
IN
Dear all,<br>

<br>

Is there a way of catching javascript errors or testing that a command is valid before trying to execute it? Can't find much info on this area.<br>

<br>

I'm trying to execute the command..<br>

<br>

window.parent.opener.location.href= ..blah blah..<br>

<br>

Which is valid sometimes but not at others depending upon the location it is trying to open. Is there some sort of try/catch command which could allow me to do something else if the command is not able to be executed, or is not valid.<br>

<br>

Thanks,<br>

Mike<br>


 
I think your main problem is that NS supports the window.location.href procedure; but M$ does not; in M$IE I beleive you have to use something like ***.location = <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= > </a><br>*nix installation & program collector/reseller. Contact me if you think you've got one that I don't :)
 
If you want to cancel the error messages from apearing then plce the fallowing code somewhere on your page:<br>
<br>
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;&lt;!--<br>
<br>
function stoperror() {<br>
return true;<br>
}<br>
window.onerror = stoperror<br>
<br>
//--&gt;&lt;/script&gt;<br>
<br>
Where you place the code depends on wether or not you are using frames or pop-up windows. If this is the case, then just put the code in whatever frame or window is causing the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top