[英]Refresh the page with javascript and GET variables
<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>
But when I enter the page I left the url like this: http://example.com/ undefined?email=undefined&pass=undefined 但是当我进入页面时,我就像这样留下了网址: http : //example.com/ undefined?email = undefined&pass = undefined
Not happening ... Anyone know the problem? 没有发生......任何人都知道这个问题? Thank you very much! 非常感谢你!
Well, what's up with document.write(…)
in here? 那么, document.write(…)
在这里有什么用? You don't want to print out anything: 你不想打印任何东西:
var email = localStorage.getItem('email');
But if you want to print out the values for testing: 但是如果你想打印出测试值:
var email = localStorage.getItem('email');
document.write(email);
(See also console.log(…)
) (另请参见console.log(…)
)
You should escape the parameters using encodeURIComponent(…)
: 你应该使用encodeURIComponent(…)
来转义参数:
location.href = url + "?email=" + encodeURIComponent(email) +
"&pass=" + encodeURIComponent(pass);
Also you should not use document.write anyhow. 另外你不应该使用document.write。 There are plenty more reasonable methods to change the content dynamically on you website. 有很多更合理的方法可以在您的网站上动态更改内容。
You should not send a password using GET requests, as they will appear the browser, proxy and server logs. 您不应使用GET请求发送密码,因为它们将显示浏览器,代理和服务器日志。 Use POST requests through invisible forms. 通过隐形表单使用POST请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.