Im trying to construct a script that will check if a url variable called result exists and if it does then it checks if the value equals success or not.
I tried the following but if result doesn't exist then it errors my script as undefined
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var first = getUrlVars()["result"];
alert(first);
And why don't you simply check if it is undefined ?
if (first !== undefined)
alert(first);
else alert('ooops');
Or you probably can also define something like a 'default value':
var first = getUrlVars().result || '';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With