簡體   English   中英

將php文件加載到彈出窗口中,並將php變量發布到該彈出窗口(使用onclick)

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

我正在嘗試將$ GLABALS變量發布到另一個php文件,並使其在彈出窗口中打開,並使用$ GLOBLAS變量的值(其傳遞$ dom使用的xml文件的名稱)加載printOnly.php文件。

當前,它打開彈出窗口,但是找不到發布的變量的值,但是它也將變量加載到現有的導航器窗口中,在那里可以毫無問題地檢索發布的變量的值。 我希望主窗口保留在原始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';
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM