trapping JS errors

Discussion in 'Javascript' started by CAFxX, Aug 22, 2003.

  1. CAFxX

    CAFxX Guest

    i wrote this code that is meant to check if the client browser generates an
    error when executing the blendtrans statement.
    unfortunately it's not working as i wished.
    this page is called check.asp and the site main page is called index.asp
    all the site's pages will use the JS cookie to decide what script will have
    to be used, the one using the blendtrans method or another one that simply
    shows/hides the obj.
    it's a mix of JS and ASP.
    thanks to everyone for your help.

    <% if request("js") = false or request.cookies("js") = false then %>
    <% response.cookies("js") = false %>
    <html>
    <head>
    <script language=javascript>
    function go_on() {
    redirect = eval(self.location="index.asp");
    return true;
    }
    </script>
    </head>
    <body onLoad="go_on()">
    </body>
    </html>
    <% else %>
    <html>
    <head>
    <title="N-Side - Checking browser">
    <link href="Gatherer.css" rel="stylesheet" type="text/css">
    <script language=javascript>
    function fadein(obj) {
    myObj = eval(obj);
    window.onError = noJS();
    myObj.filters.blendTrans.apply();
    myObj.style.visibility = "visible";
    myObj.filters.blendTrans.play();
    redirect = eval(self.location='index.asp');
    return true;
    }
    function noJS() {
    redirect = eval(self.location='check.asp?js=false'>;
    return true;
    }
    </script>
    </head>
    <body onLoad="fadein(test)" onError="noJS()">
    <div id="test" style="visibility: hidden;">
    </body>
    <% end if %>
    CAFxX, Aug 22, 2003
    #1
    1. Advertising

  2. "CAFxX" <> writes:

    > i wrote this code that is meant to check if the client browser generates an
    > error when executing the blendtrans statement.


    How is it supposed to check that?

    > unfortunately it's not working as i wished.


    What did you wish? What really happened?

    > this page is called check.asp and the site main page is called index.asp
    > all the site's pages will use the JS cookie to decide what script will have
    > to be used, the one using the blendtrans method or another one that simply
    > shows/hides the obj.
    > it's a mix of JS and ASP.


    You could just have posted the HTML, as posted to the client. The
    error should be in that part. In this case, the ASP part is so small
    and unintrusive that it is not a problem

    > <script language=javascript>


    <script type="text/javascript">
    The type attribute is mandatory and the language attribute is deprecated
    in HTML 4.

    > function go_on() {
    > redirect = eval(self.location="index.asp");


    This will probably redirect the page before the error appears, but
    it is an error. You don't need eval for anything on this page, and
    probably not on any other page you make.
    Just use:
    self.location.href="index.asp";

    If the expression inside eval hadn't redirected the page, it would
    evaluate to "index.asp", which you then try to evaluate as a
    Javascript expression. There is no object called "index", so that gives
    an error.

    > return true;


    You won't get to return either, the page is already gone.

    > }


    > <script language=javascript>


    Again type="text/javascript"

    > function fadein(obj) {
    > myObj = eval(obj);


    You don't need eval here. The value of "obj" is an object, and using
    eval on that just gives itself again. If obj had been a string, it
    would probably still not be what you wanted.

    > window.onError = noJS();


    The on-event handlers are not subcapitalized in Javascript.
    You wrote onError in the HTML tag, but that is because HTML is not
    case sensitive. Javascript is.

    You don't want to call the noJS function now, just assign it as a
    handler.

    window.onerror = noJS;

    I am not familiar with the onerror handler for windows, so I'll assume
    you know what you are doing. Ditto for blendTrans.

    > myObj.filters.blendTrans.apply();
    > myObj.style.visibility = "visible";
    > myObj.filters.blendTrans.play();
    > redirect = eval(self.location='index.asp');


    Again:
    self.location.href="index.asp";

    > return true;
    > }
    > function noJS() {
    > redirect = eval(self.location='check.asp?js=false'>;

    and again :)
    self.location.href="check.asp?js=false";

    > return true;
    > }


    > <body onLoad="fadein(test)" onError="noJS()">


    This will only work in very few browsers, those that make a
    global variable, "test", referring to the element with id="test".

    <body onload="fadein(document.getElementById('test'))" onerror="noJS()">

    > <div id="test" style="visibility: hidden;">


    Good luck
    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Aug 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlsbA==?=

    Trapping 'compile' errors when aspx page is rendered.

    =?Utf-8?B?QmlsbA==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    511
    =?Utf-8?B?QmlsbA==?=
    Mar 29, 2005
  2. Aaron Fude

    Trapping JNI errors

    Aaron Fude, Jun 1, 2004, in forum: Java
    Replies:
    4
    Views:
    1,496
    Gordon Beaton
    Jun 2, 2004
  3. Avi Kak
    Replies:
    6
    Views:
    315
    Duncan Booth
    Feb 13, 2006
  4. Eitan

    Trapping errors in ASP

    Eitan, Jan 12, 2005, in forum: ASP General
    Replies:
    6
    Views:
    131
    Bob Barrows [MVP]
    Jan 13, 2005
  5. Eitan
    Replies:
    3
    Views:
    131
    Bob Barrows [MVP]
    Jan 12, 2005
Loading...

Share This Page