将php文件加载到弹出窗口中,并将php变量发布到该弹出窗口中(使用onclick)


load a php file into a popup and post php variable to that popup (using onclick)

我正试图将$GLABALS变量发布到另一个php文件中,并在弹出窗口中打开它,然后加载带有$GLOBLAS变量值的printOnly.php文件(它传递$dom.使用的xml文件的名称

目前,它打开弹出窗口,但找不到发布的变量的值,但它也将变量加载到现有的导航器窗口中,在那里可以毫无问题地检索发布的变量值。我希望主窗口保持在原始php页面上,只将表单中调用的文件加载到弹出窗口中。

在原始页面上,我有:

<form name ="printView" method ="post" action="printOnly.php" target="popUp" >
    <input type="hidden" name="toPopFile" value="'.$GLOBALS["file"].'" />
    <input type="image" value="submit"  class="button" title="print view" src="graphics/printview.png" align="middle" onclick="javascript:viewClick(''printOnly.php'')" />
</form>

在要加载到弹出窗口的文件中,我有:

$file=basename($_POST['toPopFile']); // value to be retrieved which is the name of the xml file currently loaded in original php file
$dom = new domDocument;
if (file_exists($file)) {
    $dom->load($file);
    } else {
    exit('Error ! xml file not found.');
}

这里是从外部.js文件调用的javascript函数

var view;
function viewClick(url) {
  view= window.open(url,'view text','menubar=yes,scrollbars=yes,resizable=yes,width=640,height=700');
  view.focus();
}

救命!(保持简单,我可以很好地鹦鹉学舌,但我并不总是理解我在做什么)

您的表单已经在使用POST方法,所以我将从它开始。这意味着使用submit按钮作为真正的HTML提交按钮(即删除onclick事件)。然后在你的帖子中添加一个onsubmit处理程序:

<form name="printView" method ="post" action="printOnly.php" target="popUp" onsubmit="popup(this);">

在您的Javascript中添加此功能以创建弹出窗口,然后向其提交表单:

function popup(form) {
    window.open('', 'formpopup', 'view text','menubar=yes,scrollbars=yes,resizable=yes,width=640,height=700');
    form.target = 'formpopup';
}