Bookmarklet : Switch Between Servers But Keep The Same Path


/ Published in: JavaScript
Save to your folder(s)

Create two new bookmarks - one for dev, one for live and add the following corresponding code to each.


Copy this code and paste it in your HTML
  1. //dev
  2. javascript:f=parent.document.URL;l=false;q=false;if(f.indexOf('#')>0){l=f.substring(f.indexOf('#'),f.length);}if(f.indexOf('?')>0){q=f.substring(f.indexOf('?'),f.length);}if(l&&q||q&&!l){location.href='http://my-dev-server-path'+location.pathname+q;}else{if(l&&!q){location.href='http://my-dev-server-path'+location.pathname+l;}else{location.href='http://my-dev-server-path'+location.pathname;}}
  3.  
  4. //live
  5. javascript:f=parent.document.URL;l=false;q=false;if(f.indexOf('#')>0){l=f.substring(f.indexOf('#'),f.length);}if(f.indexOf('?')>0){q=f.substring(f.indexOf('?'),f.length);}if(l&&q||q&&!l){location.href='http://my-live-server-path'+location.pathname+q;}else{if(l&&!q){location.href='http://my-live-server-path'+location.pathname+l;}else{location.href='http://my-live-server-path'+location.pathname;}}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.