SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there a way of terminating JavaScript code in it's tracks?

    I've been doing lots of Googling and looking in my books, but can't seem to find a function that does this? I'm basically wanting to try some things out in other peoples code and I'm trying to find a way to terminate code dead in it's tracks where I want... Bit like the die() statement in PHP?

    Many thanks.

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could always throw an Error if something goes wrong. The JavaScript will stop executing after this. Is that what you want?

    Example
    Code:
    // something went terrible wrong
    throw new Error("Fatal error!");

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Install Firebug, select the "script" tab and click in the left margin to set a breakpoint.

  4. #4
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    You could always throw an Error if something goes wrong. The JavaScript will stop executing after this. Is that what you want?

    Example
    Code:
    // something went terrible wrong
    throw new Error("Fatal error!");
    That's perfect... Thank you!

    I'm on IE so I can't use the FireFox extention.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by littlejim84 View Post
    I'm on IE so I can't use the FireFox extention.
    You can install Firefox. Seriously -- Developing Javascript on IE, is an uphill battle.

    If you insist, you can use the IE script debugger.

  6. #6
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I have FireFox... Its my favourite browser. It's just the projects I work on (in my team) have developed the whole thing to work just in IE so I kinda have to use that to debug... IE Script debugger? I'll check that out. Cheers!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •