将一个php文件加载到一个弹出窗口中,并将php变量发布到该弹出窗口中(使用onclick) [英] load a php file into a popup and post php variable to that popup (using onclick)

查看:51
本文介绍了将一个php文件加载到一个弹出窗口中,并将php变量发布到该弹出窗口中(使用onclick)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将$ GLABALS变量发布到另一个php文件中,并使其在弹出窗口中打开,并使用$ GLOBLAS变量的值加载printOnly.php文件(该变量传递由$ dom.

I am trying to post the $GLABALS variable to another php file and get it to open in a popup and load the printOnly.php file with the value of the $GLOBLAS variable (which passes the name of the xml file used by $dom.

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

Currently it opens the popup but cannot find the value of the variable posted but it also loads the variable into the existing navigator window where the value of the posted variable is retrieved without a problem. I want the main window to stay on the original php page and only load the file called in the form to the popup.

在原始页面上,我有:

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

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

In the file to be loaded into the popup I have:

$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函数

And here is the javascript function being called from an external .js file

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

帮助!(并且保持简单,我可以很好地模仿,但是我并不总是了解自己在做什么)

Help! (and keep it simple, I can parrot well, but I don't always understand what I'm doing)

推荐答案

您的表单已经在使用 POST 方法,因此我将从此开始.这意味着将您的 submit 按钮用作真正的HTML提交按钮(即,放置 onclick 事件).然后在您的帖子中添加 onsubmit 处理程序:

Your form is using a POST method already, so I will start with that. It means using your submit button as a real HTML submit button (ie drop the onclick event). Then add a onsubmit handler to your post:

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

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

Add this function in your Javascript to create the popup, and then submit the form to it:

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

这篇关于将一个php文件加载到一个弹出窗口中,并将php变量发布到该弹出窗口中(使用onclick)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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