Get URL Variables/parameters values With JavaScript


javscript function ///
//name = Pass URl parameter
function getParameterByName(name) {
alert(name);
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
var result= match && decodeURIComponent(match[1].replace(/\+/g, ' '));
alert(result);
}

// ]]>


and buttun onclick event onclick=”javascript:getParameterByName(‘utm_source’);”
URL = javascript_get_parameter.html?utm_source=massmail&utm_medium=email&utm_campaign=21-feb-2015

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s