2013-02-27 42 views
-2
<a class = 'printrequest' href="printrequest.php" onclick="javascript:void window.open('printrequest.php?id=$studid','1361194834275','width=800,height=700, toolbar=0,menubar=1,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0');return false;">PRINT</a> 

這是一個鏈接,用於重定向我的鏈接以打印頁面的內容。 這可能嗎?我如何附加ID來重定向鏈接到所需的頁面ID?與頁面編號的JavaScript彈出鏈接

+0

'window.open一個GUP功能('printrequest.php?ID = $ studid'我需要調用?id = $ studid從我的數據庫獲取數據,但是它在服務器端。 – user2115802 2013-02-27 15:12:38

回答

1

有多種方法可以做到這一點我通常會在後端獲取url參數並將其傳遞給頁面。

但是,如果你想使用JavaScript,你可以使用像

function gup(name){ 
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
var regexS = "[\\?&]"+name+"=([^&#]*)"; 
var regex = new RegExp(regexS); 
var results = regex.exec(window.location.href); 
if(results == null) return ""; 
else return results[1];} 

然後

<a class = 'printrequest' href="printrequest.php" onclick="javascript:void window.open('printrequest.php?id='+gup('id')+'','1361194834275','width=800,height=700, toolbar=0,menubar=1,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0');return false;">PRINT</a> 
+0

是的,它的工作!非常感謝您的先生! – user2115802 2013-02-27 15:18:06

+0

沒問題不要忘記標記爲正確的答案和你的項目的好運。 – 2013-02-27 16:24:53