Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    23
    Member #
    25361
    Please i am confuse to understand this particular codes.
    Please help me solve this issue.Please here is the codes.
    <html>
    <head>
    <script type="text/javascript">
    var txt="";
    function message()
    {
    try
    {
    adddlert("Welcome guest!");
    }
    catch(err)
    {
    txt="There was an error on this page.\n\n";
    txt+="Click OK to continue viewing this page,\n";
    txt+="or Cancel to return to the home page.\n\n";
    if(!confirm(txt))
    {
    document.location.href="http://www.w3schools.com/";
    }
    }
    }
    </script>
    </head>

    <body>
    <input type="button" value="View message" onclick="message()" />
    </body>

    </html>

    Please where i am finding it difficult to understand is the catch(err) part....That is where we have.. \n\n", ...That is with this end codes really confuse me.
    please do help explain to me.

    Thanks.
    Clement Osei

  2.  

  3. #2
    Junior Member
    Join Date
    Nov 2010
    Posts
    23
    Member #
    24956
    the "\n" means "newline"

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Basically, try/catch is a way of isolating an error within a block of code. "try" means "try this block of code to see if it works." "catch (err)" means "if there's an error, do this stuff."

    In this case, the "try" would fail because "adddlert" is not a Javascript function and "catch (err)" would fire as a result.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:29 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com