PHP变量因为Javascript弹出不起作用

时间:2012-07-21 23:26:36

标签: php javascript session popup

我正在使用名为LeagueLink的PHP变量。当用户未登录时,我希望变量读取文本(已经有联盟...),然后是弹出窗口的链接。到目前为止它正确显示,除非我点击链接没有任何反应。我认为混合这么多的PHP和JS只是一个语法错误,但我无法弄清楚在哪里。如果可以,请帮助使弹出窗口链接正常工作...

<?php 
 // this starts the session 
 session_start();
 $_SESSION['userid'];
 $message = "";
 if ($_SESSION['userid'] == "") {
    $message = "You must create an account or sign in to play!";
    $LeagueLink = "Already have a league...<a href='JavaScript:newPopup(\"http://www.yourfantasyfootballreality.com/signin.php\");' class='two'>Sign In</a>";
 } else {
    $message = "Hello, " .$_SESSION['userid'] . " make your picks!";
 }

 ?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
        <script type="text/javascript" src="js/jquery-easing-1.3.pack.js"></script>
        <script type="text/javascript" src="js/jquery-easing-compatibility.1.2.pack.js"></script>
        <script type="text/javascript" src="js/coda-slider.1.1.1.pack.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="icon" href="http://www.indiana.edu/favicon.ico" />
        <title>YourFantasyFootballReality</title>
        <link rel="stylesheet" type="text/css" href="mystyle.css" />

    </head>
        <body>
            <?=$message?>
            <?=$LeagueLink?>
            <?=$ActionLink?>
        </body>
</html>

1 个答案:

答案 0 :(得分:1)

JavaScript:newPopup是需要定义的函数。

我认为您正在寻找的是以下内容:您无需使用javascript在新窗口中打开该页面。只需将链接的target属性设置为_blank

$LeagueLink = "Already have a league...<a href='http://www.yourfantasyfootballreality.com/signin.php' target='_blank' class='two'>Sign In</a>";

编辑:如果您希望弹出,而不是在新标签页中打开,则可以在生成后立即调整大小。将以下内容添加到您的JavaScript中。

function newPopup()
{
var url='http://www.yourfantasyfootballreality.com/signin.php';
windowProperties = "toolbar=no,menubar=no,scrollbars=no,statusbar=no,height=500px,width=500px,left=50%,top=50%";
popWin = window.open(url,'newWin',windowProperties);
}

并保持PHP与以前一样。