2012-07-21 106 views
0

现在我到了这里是脚本提醒“你已经成功登录”后,正确的登录信息后填写表格在index.php ...Javascript Alert Box in PHP。删除灰色/白色背景当警报POPS向上

在我check_login.php这些都是脚本... 到目前为止

if($count['user_type']== "agent"){ 

session_register("myusername"); 
session_register("mypassword"); 

echo '<script type="text/javascript">window.onload = function() { 
alert("You have logged in successfully!\n");}</script>'; 
echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/agent.php\">"; 
exit(); 
//header("location:pages/agent.php"); 
} 
if ($count['user_type']== "moderator"){ 

session_register("myusername"); 
session_register("mypassword"); 
header("location:pages/moderator.php"); 
} 
else { 
echo "<script type='text/javascript'>alert('Invalid Login! Please Try Again!');</script>"; 
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; 
} 

警告框完全是工作,但..我希望它弹出,而背景仍然是可见的(的index.php),点击后好的...它会重定向到一个页面,从我的代码 - >到“agent.php”

我用

echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/agent.php\">"; 

重定向成功登录的用户..

但重定向过程之前......我希望用户看到一个警告框。

我的观点是,如何让背景仍然可见时自动弹出警告框。我注意到,在Firefox中,它是在灰色BG,而在Chrome等等... BG是白色的...

请帮助。在此先感谢:|

+0

jquery-ui对话框会更简单操作.. – Gntem 2012-07-21 18:04:18

回答

2

我不认为有办法改变默认警报框的外观和感觉,但是谁说你不能自己创建。

随意根据需要进行修改。它基本上是一个自定义提醒函数,它使用两个参数,消息和一个回调函数,当警报被“OK”按钮解除时执行。

function customAlert(m,func){ 
    var d=document, 
     c=d.createElement('div'), 
     e=d.createElement('div'), 
     f=d.createElement('div'), 
     a=d.createElement('button'); 
     c.style.cssText = 'background:#fff;width:200px;height:100px;border:1px solid #bbb;border-radius:6px;position:absolute;z-index:999;top:25%;left:25%;font:13px arial;box-shadow:0 0 10px #ccc;'; 
     e.style.cssText = 'background:#ccc;padding:5px;border-bottom:1px solid #aaa;'; 
     f.style.cssText = 'text-align:center;padding:10px;'; 
     a.style.cssText = 'display:block;margin:0 auto;padding:2px 8px;'; 
     a.innerText = 'Ok'; 
     a.onclick = function(){ 
     d.body.removeChild(c); 
     func(); 
     } 
     e.innerHTML = '<b>Alert</b>'; 
     f.innerHTML = m; 
     c.appendChild(e); 
     c.appendChild(f); 
     c.appendChild(a); 
     d.body.appendChild(c); 
     return false; 
} 

customAlert('some message',function(){ 
    /*code to do when they click OK*/ 
location.href='pages/agent.php'; 
});​ 

在这里看到的例子:http://jsfiddle.net/E6h8C/

希望有所帮助。

+0

谢谢,我会试试这个 – 2012-07-23 02:17:23

0

警报弹出窗口通常会延迟页面加载。 没有任何使用原始alert()函数的解决方案。