6

Very new to Javascript but this seems to be a relatively easy task...

I want to modify a URL using a Javascript bookmarklet for Chrome, etc. Here's what I need to change it from to:

Original URL: http://www.example.com/article/url-slug-here

New URL: http://cms.example.com/article/url-slug-here

So, in short, all it needs to do is remove 'www' and add 'cms' at the start. And automatically reload the page when you click the button, if that's possible?

Any help would be greatly appreciated.

Thanks!

1 Answer 1

7

You could change window.location property which specifies the current location of the document you are viewing. A simple replace can work:

javascript:(function() { window.location=window.location.toString().replace(/^http:\‌​/\/www\./,'http://cms.'); })()
1
  • works like a charm Commented Mar 24, 2017 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .