<script type="text/javascript">
var email = document.write(localStorage.getItem('email'));
var pass = document.write(localStorage.getItem('pass'));
var url = document.write(document.URL);
document.location.href = url+"?email="+email+"&pass="+pass;
</script>
但是当我进入页面时,我留下了这样的网址:http://example.com/未定义?电子邮件=未定义&传递=未定义
没有发生...有人知道问题吗?谢谢!
好吧,这里document.write(…)
是怎么回事?您不想打印出任何内容:
var email = localStorage.getItem('email');
但是,如果要打印出值进行测试:
var email = localStorage.getItem('email');
document.write(email);
(另见console.log(…)
(
您应该使用 encodeURIComponent(…)
转义参数:
location.href = url + "?email=" + encodeURIComponent(email) +
"&pass=" + encodeURIComponent(pass);
此外,无论如何都不应该使用document.write。有很多更合理的方法可以动态更改您网站上的内容。
您不应使用 GET 请求发送密码,因为它们将显示浏览器、代理和服务器日志。通过不可见的表单使用 POST 请求。