2013-09-23 90 views
0

我一直在为此奋斗了很长一段时间,似乎无法做到正确。Javascript Bookmarklet获取网址+标题

我想要做的是创建一个书签,将页面url +标题发送到php脚本。这个PHP脚本然后回应说的信息。

我计算过,这段代码捕获URL &冠军,应该将其发送到PHPFILE.php:

javascript:location.href='PHPFILE.php; 
url='+encodeURIComponent(location.href)+'; 
title='+encodeURIComponent(document.title) 

然后我试图呼应这个像这样:

$url = $_GET['url']; 
$title = $_GET['title']; 
echo $url + $title; 

至极似乎没有工作。任何人有任何建议? 在此先感谢。

+1

你错过了你的URL路径的''部分? ''PHPFILE.php; ?url ='+ encodeURIComponent(location.href)+';' – CodingIntrigue

回答

1

您必须附加参数,像这样的 “phpfile.php URL =值&标题=数值?”

javascript:location.href='PHPFILE.php?'+ 
'url='+encodeURIComponent(location.href)+ 
'&title='+encodeURIComponent(document.title) 
+0

感谢队友。奇迹般有效。 – Jefferson

1

我强烈建议您将POST的值传给php页面。

但是,您的问题可能是格式不正确的网址,因为';'字符和空格。你可以尝试:

javascript:location.href='PHPFILE.php?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)