Posted By

Meander365 on 08/13/09


Tagged

javascript server Switch bookmarklet


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

j31415
wirenaught


Bookmarklet : Switch Between Servers But Keep The Same Path


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.