Solved

onError method doesnt seem to work

Posted on 2001-07-26
8
315 Views
Last Modified: 2006-11-17
I have a popup page that requests the URL of the page that openned it, using 'opener.location.href'.

The popup page is called on the unload of a page on my site and if a user closes the browser or goes to a site external to mine, the popup window checks the URL of new site and if it does not match my site it logs them out of the database (using ASP script).

The problem is that requesting the opener.location.href of the destination file (which works fine if the destination page is part of my site) brings up a JS Runtime error 'Permission Denied'.

I have tried using the onError method but that still causes an error message to appear on my browser (IE 5). However, the same code worked on a collegues browser (same ver of IE) and i was able to just 'return true'.

Both of us have Disable Script Debugging unticked on our browser settings.

This is the code i was using:

<script language=javascript>

function stopError()
     {
     return true
     }

onerror = stopError



if ((opener.location.href.indexOf( "www.myWebSitesURL.com" ) > 0 ) {
    alert("you are still on my site..")
}
else {
    alert("you are leaving my site..")
}

</script>



When this code is run and debugged the 'opener.location.href.indexOf' is highlighted with the error Permission Denied.

Basically, how can i get my browser to ignore the impending error message??


0
Comment
Question by:RichBisset
  • 3
  • 3
  • 2
8 Comments
 
LVL 8

Expert Comment

by:bebonham
ID: 6322140
I have also been frustrated by this

see

http://javascript.internet.com/messages/script-debugger.html

but it doesn't work!!
0
 
LVL 14

Expert Comment

by:avner
ID: 6327026
RichBisset,
In order to make the onerror work you need to turn of the debugger :
Tools >Internet Options>Advanced >Display Notification on javascript errors
Should be unchecked.

Generally the onerror is good only if you are creating a site for non-developers audience , since it's something that you cannot gurentee , the best is to use try/catch blocks in your site.

This problem might also be output of debuggers installations(Visual InterDev for example).

another thing you should do is to make an hirarchale "if " blocks for the tests, this will eleiminate the errors :

'opener.location.href.indexOf' >>
if (opener)
  if (opener.location.href)
    if (opener.location.href.indexOf('fg')!=-1)
      {
      //only then do whatever you need.
       }


0
 

Author Comment

by:RichBisset
ID: 6333241
avner,

The Display Notification is already unchecked and the problem still occurs.

I tried your code:

if (opener)
 if (opener.location.href)
   if (opener.location.href.indexOf('fg')!=-1)
     {
     //only then do whatever you need.
      }

but unfortunatly the permission denied occurred on the second line.

Any more ideas?

Many thanks
0
 
LVL 14

Expert Comment

by:avner
ID: 6334169
You should have say it's a "permission denied " error ! :)
Let me guess : Are you trying to run a script from one server to a page in a different server ?
If it's so , then this is yoour problem , javascript will just not allow such action due to security reasons.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:bebonham
ID: 6336261
okay, avner is right...

wow. I guess trapping errors is pretty worthless :(

always in the back of my head I thought this worked reliably...it was too good to be true.
0
 

Author Comment

by:RichBisset
ID: 6336842
Im running the script from my company's web server direct to my client browser. The onError method works for some of the computers here and not others. We are all using IE 4 or 5. Im using ver 5 and someone else who is also using ver 5 is able to use the script, and they seem to have the same Internet Option settings!?!

Any last ideas?
0
 
LVL 14

Accepted Solution

by:
avner earned 75 total points
ID: 6342218
1. check for different Microsoft installs.
2. comparere one by one the IE setup.
3. compare the IE sub verion.
4. operating system compare.

That's all I can think of.
0
 

Author Comment

by:RichBisset
ID: 6343596
Thanks for the advice
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery scrollTop 2 41
Google Map JavaScript API 4 40
Why does my button disappear? 3 28
window.setInterval not firing 7 30
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now