ChromeOS中document.write输出带空格URL参数时追加null问题
ChromeOS下URL含空格的参数输出时自动追加null的问题
场景说明
- 参数传递:通过URL向
print.html传递参数,示例地址:.../print.html?name=Peter%20Gram&city=Torshavn - 参数获取代码:
<script> const name = urlParams.get('name') const city = urlParams.get('city') </script>
- 页面输出代码片段:
... <tr><td>Name:<br><script>document.write(name)</script> <tr><td>City:<br><script>document.write(city)</script> ...
- 实际输出结果:
Name:Peter Gramnull
City:Torshavn
问题详情
该问题仅出现在ChromeOS系统的Chromebook设备上,Windows系统的Chrome浏览器无此异常。实际业务场景中传递5个参数,其中3个包含空格(URL中已转义为%20),这3个带空格的参数输出时都会被自动追加null,不带空格的参数则正常显示。
内容的提问来源于stack exchange,提问作者PC-Gram
相关产品推荐
相关产品推荐

