在进行location.href跳转时,如果需要传递中文或其他特殊字符,可以使用encodeURIComponent()函数进行编码,以确保跳转过程中不出现乱码或错误。例如:
var param1 = '中文';
var param2 = '特殊字符@#';
var url = 'http://example.com/page?param1=' + encodeURIComponent(param1) + '¶m2=' + encodeURIComponent(param2);
window.location.href = url;
在跳转页面接收参数时,可以使用decodeURIComponent()函数进行解码,获取原始的中文或特殊字符内容。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:location.href跳转可以取消吗