trapping JS errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CAFxX

    trapping JS errors

    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.cookie s("js") = false %>
    <html>
    <head>
    <script language=javasc ript>
    function go_on() {
    redirect = eval(self.locat ion="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=javasc ript>
    function fadein(obj) {
    myObj = eval(obj);
    window.onError = noJS();
    myObj.filters.b lendTrans.apply ();
    myObj.style.vis ibility = "visible";
    myObj.filters.b lendTrans.play( );
    redirect = eval(self.locat ion='index.asp' );
    return true;
    }
    function noJS() {
    redirect = eval(self.locat ion='check.asp? js=false'>;
    return true;
    }
    </script>
    </head>
    <body onLoad="fadein( test)" onError="noJS() ">
    <div id="test" style="visibili ty: hidden;">
    </body>
    <% end if %>


  • Lasse Reichstein Nielsen

    #2
    Re: trapping JS errors

    "CAFxX" <cafxx@n-side.it> writes:
    [color=blue]
    > i wrote this code that is meant to check if the client browser generates an
    > error when executing the blendtrans statement.[/color]

    How is it supposed to check that?
    [color=blue]
    > unfortunately it's not working as i wished.[/color]

    What did you wish? What really happened?
    [color=blue]
    > 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.[/color]

    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
    [color=blue]
    > <script language=javasc ript>[/color]

    <script type="text/javascript">
    The type attribute is mandatory and the language attribute is deprecated
    in HTML 4.
    [color=blue]
    > function go_on() {
    > redirect = eval(self.locat ion="index.asp" );[/color]

    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.h ref="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.
    [color=blue]
    > return true;[/color]

    You won't get to return either, the page is already gone.
    [color=blue]
    > }[/color]
    [color=blue]
    > <script language=javasc ript>[/color]

    Again type="text/javascript"
    [color=blue]
    > function fadein(obj) {
    > myObj = eval(obj);[/color]

    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.
    [color=blue]
    > window.onError = noJS();[/color]

    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.
    [color=blue]
    > myObj.filters.b lendTrans.apply ();
    > myObj.style.vis ibility = "visible";
    > myObj.filters.b lendTrans.play( );
    > redirect = eval(self.locat ion='index.asp' );[/color]

    Again:
    self.location.h ref="index.asp" ;
    [color=blue]
    > return true;
    > }
    > function noJS() {
    > redirect = eval(self.locat ion='check.asp? js=false'>;[/color]
    and again :)
    self.location.h ref="check.asp? js=false";
    [color=blue]
    > return true;
    > }[/color]
    [color=blue]
    > <body onLoad="fadein( test)" onError="noJS() ">[/color]

    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.getEle mentById('test' ))" onerror="noJS() ">
    [color=blue]
    > <div id="test" style="visibili ty: hidden;">[/color]

    Good luck
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...