So I’ve got this bookmarklet which allows me to quickly switch to the test server version of whatever page I’m on:
javascript:(function() {window.location=window.location.toString().replace(/^http:\/\/www\./,'http://www-test.');})()
I’d also like to be able to switch to debug mode on my webpages, so I tried making a bookmarklet as below, but it doesn’t seem to work:
javascript:(function() {window.location=window.location.toString().replace(/^php/,'php?action=debug');})()
What did I screw up?
/^php/only affects a string which starts withphp. Since thelocation.hrefproperty always includes the protocol, your code doesn’t do anything.You might be looking for
/php$/, which matches php at the end of the string.To avoid an accidental refresh upon activation of the bookmarklet, you can use: