如何使用php在新选项卡中重定向?

如何使用php在新选项卡中重定向?,php,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"]

若文件不存在但并没有重定向,但若我只写警报,那个么它就工作了,我将尝试在新页面中重新定向。请帮帮我

//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>
//php代码
document.getElementById('downloadlink')。单击();
//html代码



click()
-在元素上执行单击,就像用户手动单击它一样。在大多数浏览器中,click()仅适用于非“提交”或“重置”的表单输入元素。它不能用于模拟单击链接或表单提交按钮

downloadlink
实际上很可能是一个
链接,所以它不起作用


有关
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');

$('#downloadlink')。触发器('click');

//html代码




试试这个。我希望它能帮助你

在php中,可用于重定向:

header('location: www.google.com');
或在javascript中:

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

但我用这种方式下载了很多页面中的文件。问题是此页面仅使用哪个浏览器?抱歉,第一次出现,但仍然没有响应。这只是刷新同一页面是的,你是对的,但我想在新选项卡中打开页面,就像我们在中使用_TARGET属性一样。您的解决方案将仅在父选项卡中重定向,即在同一选项卡中。如果我使用window.open(),则我的浏览器将阻止它。我不希望这件事发生在我的客户身上,所以请帮助我
location.href = "http://www.example.com/test";