将 PHP 变量跨 javascript windows.open 传递到另一个 PHP 页面 [英] passing PHP variables across javascript windows.open to another PHP page

查看:24
本文介绍了将 PHP 变量跨 javascript windows.open 传递到另一个 PHP 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是我的变量:

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

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

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

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

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

我真正需要的是如何编辑 index.php 中的变量 $pdf_link 以便我可以将 $text1 和 $text2 或任意数量的变量传递给 <代码>create_pdf.php 页面.

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.

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

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

推荐答案

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

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

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

这篇关于将 PHP 变量跨 javascript windows.open 传递到另一个 PHP 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆