[英]Redirect PHP to new window
我有一個PHP文件report.php,該文件具有一種形式,單擊后提交即可進入reports6.php。
report6.php具有mysql的代碼,如果未找到行,則會將其重定向回帶有錯誤代碼的reports.php。
在reports6.php中,我正在使用reports.php
header ("location: reports.php")
但是,如果找到行,則設置一些參數並調用另一個php文件(cpdf.php)以再次使用標頭重定向從這些參數創建pdf。
我想要的是當用戶單擊reports.php中的Submit時。cpdf.php應該在新頁面中打開。
如果我在提交表單時在reports.php中使用target =“ _ blank”,則report6.php將在另一個選項卡中打開並生成pdf,但是如果沒有行,則report.php將在另一個選項卡中打開,提示“未找到行”。
如果我不使用reports.php中的_blank並在reports6.php中使用javascript打開cpdf.php,並將標頭重定向到reports.php,則它不起作用(我給出了允許彈出窗口,但我不知道為什么使用cpdf。 php將無法打開)。
如果我在report6.php中提供一些輸出,例如“ echo me;” 然后pdf打開正常..我想這與php和the之類的東西有關。
當我搜索其他先前詢問的問題時,無法使用標頭並在php中的新標簽頁中打開。
那么在這種情況下我該怎么辦?
謝謝。
以下是相關代碼:
Reports.php
<form name="report6" action="report6.php" onsubmit="return check_digit('report6','system_id',' System ID ')"method="post">
<td><b>Print old Invoice by System ID: </b></td>
<td><input type="text" name="system_id" ></td>
<td><input type="submit" name="Run" value="Run"></td>
</form>
Reports6.php
$sql=blah blah blah
if ( $row_cnt == 0 )
{
$mysqloutput="No such System ID in the Database";
$_SESSION["mysqloutput"]=$mysqloutput;
mysqli_close($con);
die(header ("location: reports.php"));
}
else
{ header ("location: cpdf.php"); }
cpdf.php
//生成pdf的代碼
我試過的
1)在report.php中添加target =“ _ blank”
2)在report6.php中添加<script type="text/javascript" language="Javascript">window.open("cpdf.php")</script>
我想要的是:
如果從那里提交報表,則從reports.php提交表單時,cpdf.php將在新選項卡中打開
如果沒有,則僅重定向到同一選項卡中的reports.php(在我得到的其他選項卡中不)
您無法在PHP中打開新窗口,因為它是服務器端腳本。 但是,當您希望在新窗口中打開標題時,可以將其添加到標題位置:
header("Location: reports.php?newwindow=true"); exit();
然后在您的reports.php文件中,您可以選擇該GET方法,並檢查是否設置了該方法,並使用javascript強制在新窗口中打開該窗口。
<?php if(isset($_GET['newwindow']) && $_GET['newwindow']=="true"){ ?>
<script>[... script that handles new window here ...]</script>
<?php } ?>
如果您想使用php打開一個新窗口,這里是正確的代碼
echo "<script language=\"javascript\">window.open('cpdf.php',\"_blank\");</script>";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.