JavaScript Utility

Below are few Java Script methods to help you.

Debugging in JavaScript:
Debugging in JavaScript is now become easier with modern browsers.But still you will be facing issues in many cases so the alternative can be writing print statments in javaScript (i.e. console.log(“Message”)).

But in IE browser if you console is not opened (it can be opened with Developer tools (F12)) then it will show function undefined error and will stop further javascript execution. To prevent this you can use console as below.

window.console && console.log (“Message To Log”);

Getting Param From URL
function getParam(name) {
name = name.replace(/[\[]/, “\\\[“).replace(/[\]]/, “\\\]”);
var regexS = “[\\?&]” + name + “=([^&#]*)”;
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return “”;
else
return results[1];
}

Example :

You must either modify your dreams or magnify your skills …

getParam(“load”) will return true;

Reload the Page Native Method
location.reload();

Lot more come.. Stay tuned…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: