0

I looking for a script that will detect the current url and amend the current url. Example:

find: http://example.php and replace with http://example-newstring.php

I can currently find the url replace the url using window.location but I'm stuck on how to replace the .php with new characters.

Any help greatly appreciated!!

6
  • What techniques have you tried up to this point? Can you show some of your code that you already have to help us see what else you might need? Commented Mar 12, 2012 at 16:25
  • Could you show more examples? Before/after, in addition to what you've tried so far? Commented Mar 12, 2012 at 16:25
  • You do know that amending the current url will redirect you to that page .. right ? (unless you mean inside links) Commented Mar 12, 2012 at 16:27
  • Not necessarily, if you use the HTML5 history API it doesn't. Commented Mar 12, 2012 at 16:29
  • @Magrangs, good point (although, the OP mentions window.location in the tags, and also the example alters the domain which is not possible with history API). Commented Mar 12, 2012 at 17:50

3 Answers 3

1

Try window.location.href = window.location.href.replace(".php", "-newstring.php");

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

Comments

1

HTML5 history API

try {
  window.history.pushState({}, "Alternate title", host);
} catch (e) {}

DOES NOT WORK IN IE 7-9

Comments

0

If you are using a HTML 5 compliant browser you can use the history api.

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.