簡體   English   中英

如何使用php在新標簽頁中重定向?

[英]how to redirect in new tab using php?

如果文件不存在但未重定向,我嘗試在新頁面中重新分配,但是如果我只寫警報,則它可以正常工作。 請幫我。

//php code

<?PHP 
if(isset($_POST["bills"]))
{
if($_POST[month]=='Select Month' || $_POST[year]=='Select Year'){$msg="Please select valid month or year";}
else if(file_exists($path.$_POST["month"].$_POST["year"].'.pdf')){header('location:'.$path.$_POST[month].$_POST[year].'.pdf');}
else{?>
<script type='text/javascript' language="javascript">document.getElementById('downloadlink').click();</script>
<?PHP }
}
?>

//html code

<form action="electricitybills.php" method="post" >
<select name="year">
<?PHP include('include/billsyear.php'); ?>
</select>
<select name="month">
<?PHP include('include/billsmonth.php'); ?>
</select>
<div class="gobutton"><input type="submit" name="bills" value="GO"></div>
</form>

    </div>
<br><br><br><a id="downloadlink" href="http://www.google.com" target="_blank" style="display:none;">link text</a></form>

click() -對元素執行單擊,就像用戶手動單擊它一樣。 在大多數瀏覽器中,click()僅適用於非“提交”或“重置”形式的I​​NPUT表單元素。 它不能用於模擬對鏈接或表單提交按鈕的單擊。

downloadlink實際上是一個link ,所以為什么它不起作用

請參考此鏈接以獲得click()文檔

使用jquery的.ready函數。 因為您嘗試在生成document.getElementById('downloadlink')之前訪問它。

<a id="downloadlink" href="http://www.google.com" target="_blank" style="display:none;">link text</a>
<?PHP 
if(isset($_POST["bills"]))
{
if($_POST[month]=='Select Month' || $_POST[year]=='Select Year'){$msg="Please select valid month or year";}
else if(file_exists($path.$_POST["month"].$_POST["year"].'.pdf')){header('location:'.$path.$_POST[month].$_POST[year].'.pdf');}
else{?>
<script type='text/javascript' language="javascript">
$('#downloadlink').trigger('click');

//html code

<form action="electricitybills.php" method="post" >
<select name="year">
<?PHP include('include/billsyear.php'); ?>
</select>
<select name="month">
<?PHP include('include/billsmonth.php'); ?>
</select>
<div class="gobutton"><input type="submit" name="bills" value="GO"></div>
</form>

    </div>
<br><br><br></form>

試試這個。 希望對您有幫助!

在php中,您可以用於重定向:

header('location: www.google.com');

或使用javascript:

location.href = "http://www.example.com/test";

暫無
暫無

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

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