passing PHP variables across javascript windows.open to another PHP page

家住魔仙堡 提交于 2019-12-02 15:55:55

问题


I have a PHP page index.php contains javascript window.open code to make another page create_pdf.php popup and pass some PHP variables to it to create a pdf file using FPDF

Here is my variables:

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

And here is FPDF code in the http://mysite.com/create_pdf.php page, which I need to pass PHP variables $text1 and $text2 to it from index.php page:

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

And here is the PHP variable $pdf_link which contains javascript window.open code:

$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>";

Exactly what I need is how can I edit the variable $pdf_link in index.php so I can Pass $text1 and $text2 or any number of variables to create_pdf.php page.

Note: I'm familiar with PHP but not familiar with Javascript.


回答1:


Not sure I am following but you might want to try:

$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>";

or

$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>"


来源:https://stackoverflow.com/questions/17956251/passing-php-variables-across-javascript-windows-open-to-another-php-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!