2012-07-21 29 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()函數的解決方案。