2013-09-23 89 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)