User login

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

Searched words: 
javascript replace base url javascript open path at new url javascript browser link open window with different domain javascript parse url javascript change base url path javascript remove base url greasemonkey open page with different base path selenium link check check all paths on one website on another website open site path different base url bookmarklet javascript replace function javascript replace function regular expression regular expression match to slash bookmarklet to load web path with different base bookmarklet to open web path with different base how to make a bookmarklet open in another window

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

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.