JavaScript Bookmarklet to open a web site's path in a new window with a different base URL
This is useful when manually checking each page on a site to the corresponding page on a replacement site, as the final check before taking the new site live.
Starting with the basic Drupal.org documentation-style JavaScript, and hacked at it:
javascript:u=document.location.href;t=document.title;s=window.getSelection();void(window.open(%22http://data.agaric.com/node/add/weblink?edit%5Bfield_link%5D%5B0%5D%5Btitle%5D=%22+escape(t)+'&edit%5Bfield_description%5D%5B0%5D%5Bvalue%5D='+escape(s)+'&edit%5Bfield_link%5D%5B0%5D%5Burl%5D='+escape(u),'_blank','width=725,height=500,status=yes,resizable=yes,scrollbars=yes'));
MOSTLY WORKING:
javascript:u=document.location.href;void(window.open('http://genarts.agariclabs.com:81/'+escape(u.replace(/^\/+/,%20'')),'_blank','width=725,height=500,status=yes,resizable=yes,scrollbars=yes'));
Final Version, with non-greedy matching in there between the http:// and the closing / (all those slashes escaped, which is what makes the replace look pretty crazy). Note that the target site (example.agaric etc) is hardcoded anyway so this fancy javascript regex is a little gratuitious:
javascript:u=document.location.href;void(window.open('http://example.agariclabs.com:81/'+escape(u.replace(/^http:\/\/.*?\//,%20'')),'_blank','width=725,height=500,status=yes,resizable=yes,scrollbars=yes'));
Drag that code or this link - CheckOriginal - to your browser's bookmarklet bar, modify as needed (edit the bookmark) and click whenever you want to check one site's page in the other's.
UPDATE: Dump all the width, height, etc junk in order to just let the browser handle a new window or tab as it normally would.
javascript:u=document.location.href;void(window.open('http://stage.example.com/'+escape(u.replace(/%5Ehttp:%5C/%5C/.*?%5C//,%20'')),'_blank'));
Reference:
http://www.codeproject.com/KB/scripting/replace_url_in_ajax_chat.aspx
http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#StringSelections
Comments
Great job!
Thank you for this.
It saves me a lot of work when i want to edit a page since the production server is on another location.
:-)
Post new comment