A.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> <script type="text/javascript"> //这是第一个页面a.html //通过地址栏传参的方式设置第二个页面b.html的标题为:中文 var title = "中文"; var _t = encodeURI(encodeURI(title)); window.location.href = "b.html?title="+_t; </script> </html>
B.html:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> <script type="text/javascript"> var _t = getQueryString("title"); //获取地址栏参数 var title = decodeURI(_t); //只需要转一次码 document.getElementsByTagName("title")[0].innerHTML = title; //获取地址栏参数的方法 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } </script> </html>
搬运来源:https://blog.csdn.net/sanai_1992/article/details/77336501 标签:中文,title,JS,乱码,html,参数,var,地址栏 From: https://www.cnblogs.com/liuqingxia/p/16982569.html