Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep URL parameters on Javascript redirect?

After clicking a dynamic link in an email, my users land on a page with a form pre-populated like this:

http://www.test.com/november_promo/default.html?Name=Test&Email=Test.com

A script runs right at the beginning to re-direct them to a mobile version of the page:

<script type="text/javascript" src="redirection_mobile.min.js"></script>
<script type="text/javascript">
SA.redirection_mobile ({param:"isDefault", mobile_url: "www.test.com/november_promo/default_mobile.html", mobile_prefix : "http://", cookie_hours : "1" });
</script>

Is there any way to keep those parameters when they are redirected like that?

I know there are better ways to mobile-redirect with PHP, but my company's server is sketchy about letting my department's directory serve PHP files, so we try to do everything with Javascript.

like image 657
Matt B Avatar asked Nov 08 '11 19:11

Matt B


People also ask

Can you redirect URL parameters?

You can use URL Redirect to forward your visitors to a specific page at the destination URL and pass values via query strings to the destination.

How redirect to another page and pass parameter in URL?

To redirect to another page in JavaScript, you can use window. location. href property, window. location will also work and if you want you can use window.

Can you use JavaScript to get URL parameter values?

The short answer is yes Javascript can parse URL parameter values. You can do this by leveraging URL Parameters to: Pass values from one page to another using the Javascript Get Method. Pass custom values to Google Analytics using the Google Tag Manager URL Variable which works the same as using a Javascript function.


1 Answers

document.location.search

can be used to append current location query strings to string in javascript

e.g.

<script>
var uri = 'foobar.html';

// while current location is 'baz.html?foo=1&a=b' for example

uri = uri + document.location.search;

// this will output 'foobar.html?foo=1&a=b'    
alert(uri);

</script>
like image 162
vertazzar Avatar answered Oct 18 '22 00:10

vertazzar