1

我正在尝试将 $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();
}

帮助!(保持简单,我可以鹦鹉学舌,但我并不总是明白我在做什么)

4

1 回答 1

0

您的表单已经使用了一种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';
}
于 2012-08-20T17:03:01.737 回答