0

我有一个 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 代码,我需要将 PHP 变量 $text1 和 $text2 从 index.php 页面传递给它:

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();

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

$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_linkindex.php以便我可以将 $text1 和 $text2 或任意数量的变量传递到create_pdf.php页面。

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

4

1 回答 1

1

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

$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>"
于 2013-07-30T20:07:25.707 回答