I'm trying to use javascript to complete something that i've done a ton of times in PHP.
I have two instances of urls that come into my site. One from a tracking link... and another from search or share, so on...
tracking link: www.foo.com/blog?offer=pine&sub_id=123 non paid search link: www.foo.com/blog
I'd like to detect if my link has a string, and if so pass the offer into a url within the page. In PHP i'd do this like so.
<?php
if(array_key_exists('sub_id', $array)) {
$my_variable = $array['sub_id'];
} else {
$my_variable = 'my default value';
}
?>
<a class="submitbutton" href="www.joinmywebsite.com/join?offer=pine&sub_id=<?php echo $my_variable; ?>">Join My Site</a>
Is it possible to do this with javascript? I've search and search and ever function I find either returns the value of the string parameter or it sees nothing and does nothing.
Thanks.