How to determine whether Javascript is enabled?

There are a lot of approaches to this. Lets take them one at a time:

  • Using NOSCRIPT tag: You can write a noscript tag just before your script tag to display the user a warning message. Check the code below, wherein the user will be redirected to another page if javascript is disabled:


<noscript><meta http-equiv=”refresh” content=”0; url=whatyouwant.html”></noscript>

<!–this javascript ensures that anybody that doesnt use javascript wont see the menu–>
<script type=”text/javascript”>
<!–hide script from older browsers
document.write(‘<select name=”whatever”><option>1</option><option>2</option></select>’);

  • Check out this interesting article on 15 seconds,  Creating a Server Control for JavaScript Testing by George Masselli. It explains how to create a control that verifies whether Javascript is supported and enabled. Apparently it is not easy to determine if a user disabled Javascript support for security reasons.
  • A simple concept of hiding the always visible warning message through javascript. In this case, if your browser has javascript enabled, the script will hide the message. However, if it has javascript disabled, the message will be visible always. Check the snippet below:

<body onload=”valid()”>
<form id=”form1″ runat=”server”>
<label Id=”lblWarning”>Your Browser has Disabled Scripting</label>
<script type=”text/jscript”>
function valid()
var lbl=document.getElementById(‘lblWarning’); = ‘none’;


Hope this was useful. Feel free to add on more options.

Javascript to check any redirection to another page

When the user had made some changes in the page and accidentally clicks some links on the page, you might want to warn the user about the redirection and ask his permission for the operation.

Javascript makes it quite simple to do this operation, with the help of window.onbeforeunload():

window.onbeforeunload = checkRedirection;

function checkRedirection (evt) {
var message = ‘Are you sure you want to leave?‘;
if (typeof evt == ‘undefined’) {
evt = window.event;
if (evt) {
evt.returnValue = message;
return message;

In case of jQuery you can use the code snippet below:

$(window).beforeunload(function() {
confirm(‘new message: ‘ + this.href + ‘ !’, this.href);
return false;

/* The following code also works at times – But only in jquery */

$(window).unload(function(){ alert(‘blubb’): }); //Use of unload won’t work in normal javascript in this scenario

This would fire a popup, with the message (Are you sure you want to leave?), in case user clicks on any other links or buttons in the page.

Javascript to maximise window on load

Well this is simple script to get your browser maximised onload:


<script language=”JavaScript”>
window.onload = maxWindow;
function maxWindow()
if (document.all)
else if (document.layers||document.getElementById)
if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;



I just tested it it IE. Hope this works fine in other browsers.

You can also open up a new window as maximised. Check the script snippet below:

function fullScreen(theURL) {‘testwindow.html’, ”, ‘fullscreen=yes, scrollbars=auto’);

If you would like to use jQuery here, you can use the following jQuery methods:

var height = $(window).height();
var width  = $(window).width();

Hope this helps.

How to suppress nagging javascript errors?

To suppress javascript error popups and warnings in your browser, just use the code snippet below:

<SCRIPT language=”JavaScript”>
function silentErrorHandler() {return true;}


This however has some limitation, from what i had experienced. It works well in IE, to a major extend in Firefox, but not much in Opera and Safari. Hence it would be advisable you use the jquery error handling in addition, to be on the safer side:


return true;


As far as i have seen, jquery error handling function works pretty well in all the browsers.

I would recommend you to use this only in the final production stage and not during development. Just for the simple fact that during development you would want to find the javascript errors.

Difference between Convert.ToString() and .ToString()

The main difference between these both are the fact that Convert.ToString() can handle NULL and avoid ObjectReferenceNullException, while .ToString() would break in such case.

It is always good to use the Convert object than the ToString()

Let’s have a look into the Convert.ToString() method. Using a reflector, i got hold of the Convert object below:

public static string ToString(object value, IFormatProvider provider)
IConvertible convertible = value as IConvertible
if(convertible != null)
return convertible.ToString(provider)
if(value != null)
return value.ToString();
return string.Empty

Well I guess this would clear up the reason for using the Convert object in you type conversion operations.

Internet Explorer Bugs

Internet explorer is considered as the most widely used browser over the internet. However, this buddy comes up with some weird bugs in every version of it. I will be giving you a high level view of the bugs that IE has got. To get the indepth view of these bugs, i would recommend you to go through the following site.


  1. IE non-disappearing content Bug
  2. The IE8 noscript-ghost Bug
  3. The IE5/6 Doubled Float-Margin Bug
  4. IE6 Peekaboo Bug
  5. IE 6 duplicate character Bug
  6. IE & Expanding Box Bug
  7. Guillotine Bug
  8. The Float Model Problem
  9. Three Pixel Text Jog
  10. IE & Italics
  11. Inherited margins on form elements
  12. Quirky Percentages in IE6’s Visual Formatting Model
  13. IE/Win Line-height Bug
  14. Disappearing List-Background Bug
  15. Unscrollable Content Bug
  16. Duplicate Indent Bug
  17. Escaping Floats Bug
  18. Creeping Text Bug
  19. Missing First Letter Bug
  20. Phantom Box Bug

Well these are among the most widely found bug in IE.