[英]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. 我希望通过单击将删除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 我基于在下一页中找到的代码所拥有的东西: 简单的Javascript小书签问题
So lets say I start on the following url https://www.flickr.com/photos/nasacommons/7651153916/in/set-72157630766688018 所以可以说我从以下网址开始https://www.flickr.com/photos/nasacommons/7651153916/in/set-72157630766688018
I want to end at https://www.flickr.com/photos/nasacommons/7651153916/ 我想在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 '/' 现在,由于flickr在图片网址之后使用了许多不同的位置引用,而不仅仅是'/ in / photostream',因此我希望代码替换'/ in /'以及其后的所有内容都只包含'/'
Thanks a bunch! 谢谢一群!
Try This :- 尝试这个 :-
location.href = location.href.substring(0,location.href.indexOf("in"));
OR 要么
location.href = location.href.substring(0,location.href.lastIndexOf("in"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.