html - Javascript | Link/Bookmarklet to replace current window location -


i work 3 variations of web page, 1) dev url, 2) preview/staging url, , 3) , live url.

i create link (bookmarklet?) can add bookmarks bar change part of url string (basically before page name) , load resulting url in new tab (or same tab if easier).

example: working on page dev url:

https://dev.mysite.com/cf#/content/www/page1.html 

i able click link , have page reload , return following staging url in same or new window/tab:

https://preview2.mysite.com/page1.html 

and if click link again, page reload , return following live url in same or new window/tab:

http://www2.mysite.com/page1.html 

and if click link again, page reload , return following dev url in same or new window/tab:

https://dev.mysite.com/cf#/content/www/page1.html 

so, avoid lot of cut/copy , paste when changing through these variations of url while developing, testing, , visiting live versions of page.

here far.. stuck on basic aspect of it, if on dev page, reload preview page:

a variation of method joewiz.org "fixing-urls-with-dns-errors" , 1 stack user63503 "how replace part of url javascript?" , after trying str.replace w3schools.

javascript:(function(){window.location.url.replace("dev.mysite.com/cf#/content/www/","preview2.mysite.com/");})(); 

or

javascript:(function(){window.location.pathname.replace("dev.mysite.com/cf#/content/www/","preview2.mysite.com/");})() 

thats 1 of steps can tell , i'm stuck. have tried many variations cannot replace specific part of url, let alone add rules reload dev, preview, live depending on current browser is.

i realize similar questions have been asked, i'm afraid unable able extrapolate actionable information ones have found. however, please let me know if feel previous post relevent , i'll head on there , study-up.

thank much!!

your code should work.

but try this

javascript:(function(){var loc=location.href;loc=loc.replace('dev.mysite.com/cf#/content/www/','preview2.mysite.com/'); location.replace(loc)})() 

remember copy url of real bookmark - send people web page can drag quotes indeed important:

<a href="javascript:(function(){var loc=location.href;loc=loc.replace('dev.mysite.com/cf#/content/www/','preview2.mysite.com/'); location.replace(loc)})()">replaceurlbm</a> 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -