Results 1 to 3 of 3

Thread: No Errors JavaScript

  1. #1
    Join Date
    May 2006
    Posts
    259
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default No Errors JavaScript

    If you get an error on one of your pages and don't know how to fix it you could try simply placing the following at the very bottom of your page.



    <SCRIPT LANGUAGE="JavaScript">

    function CC_noErrors() {
    return true;
    }
    window.onerror = CC_noErrors;
    // -->
    </SCRIPT>


    "Only dead fish flow with the stream".
    - Unknown

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    But then you'd never know the error of your ways . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Better expressed as:
    Code:
    <script type="text/javascript">
      window.onerror = null;
    </script>
    However, it's still a stupid idea. It wouldn't magically cause the script to work, so you'd have a broken script with no apparent cause.
    It's better for users to see errors and report them to you; that way, you've no problem.
    Code:
    <script type="text/javascript">
      window.onerror = function(e, url, line) {
        var message = "An error occured in " + url + ", line " + line + ", using " + navigator.userAgent + ":\n\t" + e.toString().replace(/\n/g, "\n\t"),
          subject = "An error occurred in your site",
          address = "youATyourdomainDOTcom".replace("AT", "@").replace("DOT", "."),
          response = window.confirm("An error has occurred.  Would you like to report it?  On clicking OK, an email containing all the necessary information will be composed and given to you for review.");
        if(response) {
          window.location.href = "mailto:" + address + "?Subject=" + escape(subject) + "&body=" + escape(message);
          return true;
        } else return false;
      }
    </script>
    Untested.
    Last edited by Twey; 05-10-2006 at 04:59 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •