Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mulitple Custom Error Messages

    I have designed a custom error message box for one of my websites. I have set it up, so that if there is an error on the page, it will trigger a script that opens a new window... etc.

    Here is an example:
    Code:
    function errorReport()
    {
    	var errorContent=''; // To clear the variable.
    
    	errorContent+='<html><body>';
    	errorContent+='This Is My Error Message<br>';
    	errorContent+='</body></html>';
    
    	var errWin=window.open('', 'errorWindow', 'width=650,height=300');
    	errWin.document.write(errorContent);
    	errWin.focus();
    }
    
    window.onerror=errorReport;
    This part works all fine and dandy.

    The problem is that if I have 2 errors on a single page, the error message window will double-draw. If I have 3 errors on a single page, it will triple-draw.

    My question is, is there a way to only make the error message popup once, regardless of how many errors there are?

    For an example, go to www.GoldenRuleProduce.com, and in the location bar type something like:
    Code:
    javascript:document.write('
    This will trigger the error message, but it also causes another error to occur, and the error message double-draws.

    Any help would be appreciated.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe have a global that is set when onerror fires...and checked too
    Code:
    var errorOnce = 0;
    function errorReport()
    {
    	if (errorOnce) return;
    	errorOnce = 1;
    	var errorContent=''; // To clear the variable.
    
    	errorContent+='<html><body>';
    	errorContent+='This Is My Error Message<br>';
    	errorContent+='</body></html>';
    
    	var errWin=window.open('', 'errorWindow', 'width=650,height=300');
    	errWin.document.write(errorContent);
    	errWin.focus();
    }
    
    window.onerror=errorReport;

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Passing an argument to your function where the errorMsg is combining of all your errors.

    1) Declare a variable
    var error = false;

    2) When error happenedand set it to TRUE
    error = true;
    errorMsg = "your first error"

    3) If you get a second error
    errorMsg = errorMsg + "second error";

    4) Call the errorReport at the end
    if (error)
    errorReports(errorMsg);




    function errorReport(errorMsg)
    {
    var errorContent=''; // To clear the variable.

    errorContent+='<html><body>';
    errorContent+=errorMsg<br>';
    errorContent+='</body></html>';

    var errWin=window.open('', 'errorWindow', 'width=650,height=300');
    errWin.document.write(errorContent);
    errWin.focus();
    }

    window.onerror=errorReport;

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys. Actually, beetle's idea is what I want to work with. I'll give it a try. Thanks!


  •  

    Posting Permissions

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