简体   繁体   中英

How to replace the forward slash in a javascript bookmarklet

I am not a programmer, but know a little here and there. This is a bookmarklet I have in my browser. It is supposed to take the url of the page I am on, and when clicked, takes me to another site (example.com), and pass this first site into the url of the second site (eg sitechecker.com).

Problem is, the trailing slash on the example.com/ prevents sitechecker from working, so i need to get rid of the trailing slash somehow when its passed to the other site.

Eg
No Good http://www.example.com /

Good http://www.example.com

Bookmarklet code:

javascript:(function(){ var url=location.href; var url=url.replace(/^(http|https):\/\//i,''); window.open('https://www.widgetfactory.com/index.html/all//'+encodeURIComponent(url)+'/Oc?l=us')})();

Try the following regex url.replace(/\\/$/, ""); Exm. below

var url = 'http://www.example.com/';
console.log(url.replace(/\/$/, ""));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM