There comes a time where you will want to get a value out of the URL. Its a very easy process, just use the function below.

function getParameterByName( 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 decodeURIComponent( results[ 1 ].replace( /\+/g, " " ) );
}
};

The name value is the parameter from the URL that you want. For example in the following URL: http://www.awesomesite.com?userId=’1234′ if you wanted the value for userId you just pass ‘userId’ as the parameter to this method.

On your website you are looking for a way to notify your user that they are about to navigate away from your site and that any information that has not been saved will be lost.

The solution is really simple. Just listen for the ‘onbeforeunload’ event.

My example here is using jQuery.

$( window ).bind( "beforeunload", function () {
return 'All unsaved data will be lost.'
} );

Confirm Navigation

This may seem like a JavaScript 101 topic but this was currently something I struggled with the last couple of days, and I thought that if finding a solution for this task was hard for me then it might also be hard for other people.

What I was looking to do was this: Open a new window (child) that displays data that are passed from the initial window (parent).

I was able to find solutions on how to read values out of textboxes between the parent window and the child, but that would not work for me. I need to be able to pass arrays of objects and other values that are too big or just won’t fit in a textbox.

Here is the solution I came up with:

In the parent window before you call window.open() to create a new browser window/tab you need to create a new property on the window object.
window.foo = arrOfObjects;
window.open( ‘newWindowToShow.html’, ” );

Now to access the new property in the child window, you just need to reference the window.opener object.
var myNewListOfObjects = window.opener.foo;

That’s it. Now in the your new (child) window/tab you will have access to you values.

Make sure that when you are done using the values in your new window that you set the values to null. I noticed some issue when I didn’t do that.
window.opener.foo = null;