Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Not happening ... Anyone know the problem? Thank you very much!

like image 946
Hector Segarra Avatar asked May 01 '26 02:05

Hector Segarra


1 Answers

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);

(See also console.log(…))

You should escape the parameters using encodeURIComponent(…):

location.href = url + "?email=" + encodeURIComponent(email) +
                "&pass=" + encodeURIComponent(pass);

Also you should not use document.write anyhow. 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. Use POST requests through invisible forms.

like image 60
kay Avatar answered May 02 '26 14:05

kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!