Search code examples
javascripturlflickr

Javascript bookmarklet to remove a portion of url


I would greatly appreciate any help with a script that I intend to run by clicking a bookmark that will remove the end part of a flickr url.

I presently have the following code

javascript:(function(){location.href=location.href.replace('/in/photostream', '/')})();

I based what I have with the code I found on the following page:Simple Javascript bookmarklet question

So lets say I start on the following url https://www.flickr.com/photos/nasacommons/7651153916/in/set-72157630766688018

I want to end at https://www.flickr.com/photos/nasacommons/7651153916/

Now since flickr uses many different location references after the image url other than just '/in/photostream' I am looking to have the code replace '/in/' and everything that follows it with just '/'

Thanks a bunch!


Solution

  • Try This :-

    location.href = location.href.substring(0,location.href.indexOf("in"));
    

    OR

    location.href = location.href.substring(0,location.href.lastIndexOf("in"));