1

I am using the following code to dynamically change the text on my clients website (www.mydomain.com.au):

<script type="text/javascript">// <![CDATA[
       var url = window.location.toString();
       var query_string = url.split("?");
               if (query_string[1]) {
       var params = query_string[1].split("&#038;");
       var param_item = params[0].split("=");
       param_item[param_item[0]] = unescape(param_item[1]);
       document.write(param_item["city"]);
               } else {
                       document.write("24 Hour Glass Replacement");
               }
// ]]&gt;</script>

It works perfectly fine on the index page. e.g. www.mydomain.com.au/?city=test

but when I am using the same code on other pages e.g. http://www.mydomain.com.au/Brisbane.html/?city=test I get a 404 error.

Appreciate any help

1
  • it's totally logic... you only use the QUERY-String, "all which is prefixed by the '?'". you'll have to check, if there is a query-string and parameter called "city" and if not, use the LAST word after a slash and before the file-suffix. Commented Mar 7, 2013 at 4:02

1 Answer 1

1

Remove the / before starting querystring. So, try http://www.mydomain.com.au/Brisbane.html?city=test instead of http://www.mydomain.com.au/Brisbane.html/?city=test

Sign up to request clarification or add additional context in comments.

7 Comments

normally that / would not cause a problem, but that could be why you are getting a 404.
I would also recommend you use location.search instead of parsing the entire url.
@MohammadMoezzi please do not forgot to select it as answer and vote if you think my answer is correct and helpful. thanks :)
@Shahdat unfortunately I do not have a voting power yet but I promise I'll do it when I could. Thanks
@MohammadMoezzi yes, I see but you can click on the tick to select it as answer of your question. thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.