使用javascript和GET变量刷新页面 [英] 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>
但是当我进入页面时,我离开了这样的网址:
http://example.com/ undefined?email = undefined& pass = undefined
But when I enter the page I left the url like this: http://example.com/undefined?email=undefined&pass=undefined
没有发生......任何人都知道这个问题?非常感谢!
Not happening ... Anyone know the problem? Thank you very much!
推荐答案
那么, document.write(...)
在这里?您不想打印任何内容:
Well, what's up with document.write(…)
in here? 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);
(另见 console.log(...)
)
您应该使用 encodeURIComponent(...)
:
You should escape the parameters using encodeURIComponent(…)
:
location.href = url + "?email=" + encodeURIComponent(email) +
"&pass=" + encodeURIComponent(pass);
无论如何你也不应该使用document.write。有很多更合理的方法可以在您的网站上动态更改内容。
Also you should not use document.write anyhow. There are plenty more reasonable methods to change the content dynamically on you website.
您不应该使用GET请求发送密码,因为它们会显示浏览器,代理和服务器日志。通过不可见的表单使用POST请求。
You should not send a password using GET requests, as they will appear the browser, proxy and server logs. Use POST requests through invisible forms.
这篇关于使用javascript和GET变量刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!