简体   繁体   中英

javascript get href.replace the middle string

my url is http://localhost:8080/?usrType=t#52773890547536126

i want output as httplocalhost808052773890547536128

i have tried this in javascript

config.channel = config.channel || location.href.replace(/\/|:|#|%|\.|\[|\]/g,'');

it gives httplocalhost8080?usrType=t52773890547536126

You need to replace everything between ? and # in addition to removing all those special characters.

config.channel = config.channel || location.href.replace(/\?.*?#|[\/:#%.\[\]]/g,'');

You can use the character set [\\/:#%.\\[\\]] instead of all those single-character alternatives.

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