I have the following Javascript. The document.location statement produces an error as the URL does not exist. I thought that a try/catch block would catch any errors. However, this does not work. Any ideas how I avoid this error and to continue processing the rest of the script?
<script type="text/javascript">
function foo()
{
try
{
document.location='non-existing-site.com';
}
catch(err)
{
}
}
</script>
When you change the location you just redirected…
The error handling needs to be in the new page. In your example in
'non-existing-site.com'The HTML and javascript of the previous page is irrelevant at this point.
You can open the new page in a child window if you like to (Though pop-up is Yuck…)