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  

Comments

RSS Icon Subscribe to comments
Posted By: johndonahue on December 10, 2009

Here's a way to do the same thing but with one bookmarklet. Let me know if you see any limitations to this approach.

javascript:(function(){var d='localhost';var p='mydomain.com';var s=document.domain.indexOf(d)!=-1?p:document.domain.indexOf(p)!=-1?d:0;if(s)location.href=document.location.toString().replace(document.domain,s);})()

http://snipplr.com/view/24448/server-switcher-bookmarklet/ also posted here: http://hacklite.com/2009/12/server-switching-bookmarklet/

You need to login to post a comment.