简体   繁体   English

Javascript Bookletlet-从输入中删除空格

[英]Javascript Bookmarklet - remove spaces from input

I am pretty new to this so please take it easy on me. 我对此很陌生,所以请放轻松。

I have a javascript bookmark that I use to look up tracking number for parcels on Purolators website (Canadian shipping company). 我有一个JavaScript书签,可用于在Purolators网站(加拿大货运公司)上查找包裹的跟踪号。 What I want it to do is to take the input (tracking number) and remove any spaces in it before opening the URL. 我想要它做的是在打开URL之前先输入输入(跟踪号)并删除其中的所有空格。 The tracking site is stupid and uses spaces as delimiters for new tracking numbers. 跟踪站点是愚蠢的,并使用空格作为新跟踪号的分隔符。

Also, as a bonus, can this be made to open in a new tab? 另外,作为奖励,可以在新标签页中打开它吗?

javascript:var%20trackID%20=%20escape(prompt('Enter%20Tracking%20#'));window.location='https://eshiponline.purolator.com/SHIPONLINE/Public/Track/TrackingDetails.aspx?pin='%20+%20trackID;

I have tried adding trackID%20=%20trackID.replace(/\\s+/g,%20''); 我尝试添加trackID%20=%20trackID.replace(/\\s+/g,%20''); before the window.location but no luck. window.location之前,但是没有运气。

Any ideas? 有任何想法吗?

You don't need to use escape in this scenario. 在这种情况下,您不需要使用escape This is actually replacing your spaces with %20 special characters which is why your replace wasn't working 这实际上是用%20个特殊字符替换您的空格,这就是replace无法正常工作的原因

Check http://www.w3schools.com/jsref/jsref_escape.asp for more info. 检查http://www.w3schools.com/jsref/jsref_escape.asp以获取更多信息。

Your corrected code should be something like 您更正的代码应类似于

javascript:var trackID=prompt('Enter%20Tracking%20#').replace(/ /g,"");window.location='https://eshiponline.purolator.com/SHIPONLINE/Public/Track/TrackingDetails.aspx?pin='+trackID;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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