Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add query string to URL redirect

I am trying to use a query string which I can successfully do unless it is a mobile page. What I am doing is checking if it is mobile and redirecting. Is there a way to attach the query string to the redirect url?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">// <![CDATA[  
    var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) {  
        document.location = "http://www.xxxxxxx.com/mobile";  
    }  
// ]]></script> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>xxxxxxxxx</title>

<script type="text/javascript">
    window.onload = function(){
        var total = 0;
        for(var x = 0; x < parameters.length; x++){
            document.getElementById("customerID").value = parameters[x].value;
        }
        document.forms[0].onsubmit = validate;  
    }
</script>
like image 370
shinjuo Avatar asked May 17 '13 21:05

shinjuo


People also ask

Can you redirect URLs with 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.

Does URL path include query?

pathname. The pathname property of the URL interface is a string containing an initial / followed by the path of the URL, not including the query string or fragment (or the empty string if there is no path).

What is a query string in URL example?

On the internet, a Query string is the part of a link (otherwise known as a hyperlink or a uniform resource locator, URL for short) which assigns values to specified attributes (known as keys or parameters). Typical link containing a query string is as follows: http://example.com/over/there? name=ferret.


1 Answers

I think this might be what you want..

var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
if (mobile) {
  window.location = "http://www.xxxxxxx.com/mobile" + window.location.search + window.location.hash;
}

I simplified this as window.location.search is either a blank string or starts with ?. Same goes for .hash

If your starting URL was http://www.some.com/entry?id=10 the redirect would be http://www.some.com/mobile?entry?id=10

Same goes for hashes

http://www.some.com/entry?id=10#paragraph2 would redirect to http://www.some.com/mobile?id=10#paragraph2

If the current URL does not contain either the redirect URL will remain as is.

like image 105
Morgan ARR Allen Avatar answered Oct 30 '22 21:10

Morgan ARR Allen