在另一个标签中打开一个链接

I have a button that allows authentication from twitter, everything works properly, but the only issue is that i wish to open the login-twitter.php page on a different tab, i tried using window.open in place of header but it didn't work. can anyone tell how it can be done

<?php 
ob_start();
session_start(); 
if (isset($_SESSION['id'])) {
    header("location: u_tasks.php");
}

if (array_key_exists("login", $_GET)) 
    {
        $oauth_provider = $_GET['oauth_provider'];
            if ($oauth_provider == 'twitter') 
                {
                    header("Location: login-twitter.php");
                } 
    }
?>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<?
    echo "<div class='col-md-9'>";
        echo "<a href='?login&oauth_provider=twitter'><button style='background-color:#1dcaff; border-color:#1dcaff; color:white; height:30px; border-radius:10px;'>Go To Twitter</button></a>";
    echo "</div>";
?>
</body>
</html>
dragon456101
dragon456101 只是一个建议:你的代码可能会更好,如果,而不是重定向,你只是做了一个GET或POST请求,并根据返回做了一些事情。
5 年多之前 回复

2个回答

i think it is helpful to you.

<a href='?login&oauth_provider=twitter' target="_blank"><button style='background-color:#1dcaff; border-color:#1dcaff; color:white; height:30px; border-radius:10px;'>Go To Twitter</button></a>

using header("Location:..."); can only do redirects. As far as I know, you'll have to do some amount of javascript or html to achieve your goal. Another problem is that browsers like to block automatically opened popups because 99% of the time automatic popups are used only by spammers. However, I'll show you a way to attempt to do this anyways:

<?php
$usingTwitter=0;
ob_start();
session_start(); 
if (isset($_SESSION['id'])) {
    header("location: u_tasks.php");
}

if (array_key_exists("login", $_GET)) 
    {
        $oauth_provider = $_GET['oauth_provider'];
            if ($oauth_provider == 'twitter') 
                {
                    $usingTwitter=1;
                } 
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script>
    <?php
        if($usingTwitter){
            echo "window.open('login-twitter.php');";
        }
    ?>
<script>
</head>
<body>
<?
    echo "<div class='col-md-9'>";
        echo "<a href='?login&oauth_provider=twitter'><button style='background-color:#1dcaff; border-color:#1dcaff; color:white; height:30px; border-radius:10px;'>Go To Twitter</button></a>";
    echo "</div>";
?>
</body>
</html>

Make sure you turn off popup blocking in your browser for this to work though!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐