将PHP变量传递到javascript windows.open到另一个PHP页面

时间:2013-07-30 19:58:53

标签: php javascript window.open

我有一个PHP页面index.php包含javascript window.open代码,可以弹出另一个页面create_pdf.php并将一些PHP变量传递给它以使用FPDF创建一个pdf文件

这是我的变量:

$text1 = "this is text1";
$text2 = "this is text2";

这是http://mysite.com/create_pdf.php页面中的FPDF代码,我需要从index.php页面将PHP变量$ text1和$ text2传递给它:

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40, 10, $text1);
$pdf->ln();
$pdf->Cell(40,10, $text2);
$pdf->Output();

这是PHP变量$pdf_link,其中包含javascript window.open代码:

$pdf_link = "<div class=\"pdf-box\"><a target=\"_blank\"  
onclick=\"return !window.open(this.href, 'pdf', 'width=640,height=300')\" 
href=\"http://mysite.com/create_pdf.php\"; 
return false;\">Create pdf</a></div>";

我需要的是如何编辑$pdf_link中的变量index.php,以便我可以将$ text1和$ text2或任意数量的变量传递到create_pdf.php页面。

注意:我熟悉PHP,但不熟悉Javascript。

1 个答案:

答案 0 :(得分:0)

不确定我是否关注,但您可能想尝试:

$pdf_link = "<div class=\"pdf-box\"><a target=\"_blank\"  
onclick=\"return !window.open(this.href, 'pdf', 'width=640,height=300')\" 
href=\"http://mysite.com/create_pdf.php?text1=" . urlencode($text1)  .  "&text2=" . urlencode($text2)  .  "\"; 
return false;\">Create pdf</a></div>";

$fullLinkWithParams = urlencode("http://mysite.com/create_pdf.php?text1=" . $text1  .  "&text2=" . $text2);

$pdf_link = "<div class=\"pdf-box\"><a target=\"_blank\"  
onclick=\"return !window.open('" . $fullLinkWithParams  .  "', 'pdf', 'width=640,height=300')\">Create pdf</a></div>"