简体   繁体   English

将编码的url作为参数javascript函数传递

[英]Passing encoded url as parameter javascript function

JS fiddle created at https://jsfiddle.net/ankitwasankar/sc50ecyf/ demonstrates, how the url sent as a parameter decode itself inside function. https://jsfiddle.net/ankitwasankar/sc50ecyf/创建的JS小提琴演示了如何将作为参数发送的url本身在函数内部解码。 Is it the expected behaviour. 这是预期的行为吗? Do I need to encode url passed as parameter again inside function. 我是否需要在函数内再次编码作为参数传递的url。 Currently when URL is opened with window.location.href it doesn't contain %26 instead contains & . 当前,当使用window.location.href打开URL时,它不包含%26而是包含& So on server, HttpServletRequest.getParameterNames() returns two parameters instead of one. 因此,在服务器上, HttpServletRequest.getParameterNames()返回两个参数,而不是一个。

What about split %26 in-between, like: 如何在它们之间拆分%26 ,例如:

<a href='javascript:print_me("https://www.google.co.in/search?query=a%2" + "6b=26")'>Click</a>

This prevents the auto-decoding, although it's a little bit hacky. 尽管有点麻烦,但这可以防止自动解码。

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

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