Home Ask Login Register

Developers Planet

Your answer is one click away!

user3664644 February 2016

javascript windows.location string picking

I have this URL:


And I will need get that using Javascript

var locat = window.location.href;     
$.get("enviaramigo.php?email="+$("#email").val()+"&url="+locat, function(html) {

But, when I use the locat var, I will get this incomplete URL:


How to I get the complete URL?



jcubic February 2016

You need to encode the url using encodeURIComponent

var locat = window.location.href;     
$.get("enviaramigo.php?email="+$("#email").val()+"&url="+encodeURIComponent(locat), function(html) {

or base64

$.get("enviaramigo.php?email="+$("#email").val()+"&url="+btoa(locat), function(html) {

and you will need to decode on the sever.

Post Status

Asked in February 2016
Viewed 3,300 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life