How to encode periods for URLs in Javascript?

后端 未结 8 2003
耶瑟儿~
耶瑟儿~ 2020-12-15 15:29

The SO post below is comprehensive, but all three methods described fail to encode for periods.

Post: Encode URL in JavaScript?

For instance, if I run the th

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 16:20

    Periods shouldn't break the url, but I don't know how you are using the period, so I can't really say. None of the functions I know of encode the '.' for a url, meaning you will have to use your own function to encode the '.' .

    You could base64 encode the data, but I don't believe there is a native way to do that in js. You could also replace all periods with their ASCII equivalent (%2E) on both the client and server side.

    Basically, it's not generally necessary to encode '.', so if you need to do it, you'll need to come up with your own solution. You may want to also do further testing to be sure the '.' will actually break the url.

    hth

提交回复
热议问题