title: Javascript Redirect - Keep Path and Variables, Switch Domain
body: <p>I am trying to do a mobile redirect using javascript.  Here is what I am trying to accomplish:</p>
  
  <p>Normal View:
  <a href="https://secure.example.com/checkout/Checkout.aspx?a=1&amp;b=2&amp;c=3&amp;d=456789" rel="nofollow">https://secure.example.com/checkout/Checkout.aspx?a=1&amp;b=2&amp;c=3&amp;d=456789</a></p>
  
  <p>Redirected to</p>
  
  <p>Mobile View:
  <a href="https://differentdomain.com/mobile/Checkout.aspx?a=1&amp;b=2&amp;c=3&amp;d=456789" rel="nofollow">https://differentdomain.com/mobile/Checkout.aspx?a=1&amp;b=2&amp;c=3&amp;d=456789</a></p>
  
  <pre><code>        &lt;script type="text/javascript"&gt;
              function TN_mobileUrlOverride()
                  {
                      TN_mobile.DroidUrl = TN_mobile.IphoneUrl = TN_mobile.BlackBerryUrl = "https://example.com/mobile" + window.location;
                  }
          &lt;/script&gt;
          &lt;script src="http://s3.amazonaws.com/TNService/Js/mobile.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>When I use window.location, it adds the entire domain resulting in:
  <a href="https://example.com/mobile/https://differentdomain.com/mobile/Checkout.aspx?a=1&amp;b=2&amp;c=3&amp;d=456789" rel="nofollow">https://example.com/mobile/https://differentdomain.com/mobile/Checkout.aspx?a=1&amp;b=2&amp;c=3&amp;d=456789</a></p>
  
  <p>When I use window.location.path, it doesn't carry the variables, only the file:
  <a href="https://differentdomain.com/mobile/Checkout.aspx" rel="nofollow">https://differentdomain.com/mobile/Checkout.aspx</a></p>
  
  <p>How can I keep the file and url parameters while replacing the domain?</p>
  
  <p>Thank you!</p>