drryyiuib43562604 2018-08-25 15:22
浏览 26

将用户重定向到php中的新窗口

I have a authentication device that on successful transaction returns only ok. If the output is anything else but ok, it won't work and throw error.

On successful transaction it's redirected to page cams-attendance.php which returns the value ok.

<?php
echo 'ok';
?>

I want to redirect the user to a another page in a new window. I tried header, but header cannot redirect to a new window. I've tried javascript. But as it's more than ok, I'm getting error.

<?php
echo 'ok';
?>
<script type="text/javascript" language="Javascript">window.open('http://www.example.com');</script>

using this code, the output is -

ok
<script type="text/javascript" language="Javascript">window.open('http://www.example.com');</script>

So, as it's printing more than ok, the device is throwing error.

How can I achieve this.

  • 写回答

2条回答 默认 最新

  • doutan5724 2018-08-25 15:34
    关注

    I assume that your final variable is $resp and I have assigned the value "ok" to it. Here I check to see whether the $resp is equal to "ok" and if there is a match I echo out the javascript which pops up the new website on page load.

    <?php $resp = "ok";
     if($resp=="ok"){
    ?>
    <script>
       window.onload = function() {
          window.open('http://www.example.com');
       };
    </script>
    <?php } ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮