开发者

Bookmarklet to swap (live and testing) URLs in browser

I used to use the following bookmarklet code to swap URLs between my site's staging server and live server, so I could test that staged pages had been successfully pushed live:

Staging URL: www.stage.site.com/folder/page.html

Live URL: www.site.com/folder/page.html

Here's the code for that bookmarklet; the script wo开发者_开发技巧rks in both directions: stage to live and live to stage:

javascript:if(location.host=='www.site.com')(location.href='http://www.stage.site.com'+location.pathname);if(location.host=='www.stage.site.com')(location.href='http://www.site.com'+location.pathname);

However, my site architecture has changed (CMS) and the staging URL is now quite different from the live URL:

Authoring URL: author.site.com/bucket1/bucket2/bucket3/folder/page.html

Live URL: www.site.com/folder/page.html

I haven't been able to figure out how to rewrite that bookmarklet code so it can handle the truncated pathname.


Try

javascript:if(location.host=='www.site.com')(location.href='http://author.site.com/bucket1/bucket2/bucket3'+location.pathname);if(location.host=='author.site.com')(location.href='http://www.site.com'+(location.pathname.split('/').slice(4).join('/')));

I'm assuming that bucket1/bucket2/bucket3/ remains constant, or else you'll need to figure out some devilishly clever way of storing that information.

You could also do a string replace on location.pathname, but I just felt like using split/slice/join.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜