tugberk tugberk - 1 year ago 102
Javascript Question

hide javascript error from browser

I found this code sample on one of the questions;

window.onerror = function (msg, url, linenumber) {

//make ajax call with all error details and log error directly into the elmah database

//show freindly error msg here to user

//hide error from browser
return true;

What does 'hide error from browser' means and how can I do that?

I didn't know such a thing exists and I give it a try with try-catch block. After an error occurred, I realized that browser still shows the error. how can I hide error from browser


I tried following code and put that inside the head section of my all pages but noting happened;

<script type="text/javascript">

(function () {

window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {


// Just let default handler run.
return true;



Answer Source

When the function returns true, this prevents the firing of the default event handler.

It's just the way the browser behaves if this function returns true.

See more