3

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!

3

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.'); })()

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.