You must append parameters like this "phpfile.php?url=value1&title=value2"
javascript:location.href='PHPFILE.php?'+
'url='+encodeURIComponent(location.href)+
'&title='+encodeURIComponent(document.title)
Question
I've been struggling with this for quite some time now, and can't seem to get it right.
What I'm trying to do is create a bookmarklet which sends the page url + title to a php script. This php script then echoes said information.
I figured that this piece of code catches the url & title and should send it to the PHPFILE.php:
javascript:location.href='PHPFILE.php;
url='+encodeURIComponent(location.href)+';
title='+encodeURIComponent(document.title)
I then tried to echo this like so:
$url = $_GET['url'];
$title = $_GET['title'];
echo $url + $title;
Which doesn't seem to work. Anyone got any suggestions?
Solution
You must append parameters like this "phpfile.php?url=value1&title=value2"
javascript:location.href='PHPFILE.php?'+
'url='+encodeURIComponent(location.href)+
'&title='+encodeURIComponent(document.title)
OTHER TIPS
I would strongly advise you to POST the values to the php page.
However, your problem is probably a malformed url because of the ';' characters and whitespace. You could try:
javascript:location.href='PHPFILE.php?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)