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?
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)
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.