dou11655853
dou11655853
2015-01-31 06:38
浏览 36

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

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>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxiao3694
    dongxiao3694 2015-01-31 06:47
    已采纳

    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>
    
    点赞 评论
  • donglugou6652
    donglugou6652 2015-01-31 06:52

    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!

    点赞 评论

相关推荐