2012-07-26 38 views
0

因爲用戶沒有給出任何輸入我米顯示彈出消息給我的窗口使用JavaScript像下面關閉Windows用戶界面彈出消息

var msg = new Windows.UI.Popups.MessageDialog("No internet connection has been found."); 
msg.commands.append(new Windows.UI.Popups.UICommand("Try again", commandInvokedHandler)); 
msg.commands.append(new Windows.UI.Popups.UICommand("Close", commandInvokedHandler)); 
msg.defaultCommandIndex = 0; 
msg.cancelCommandIndex = 1; 
msg.showAsync(); 

現在我想一些一個時間間隔後編程關閉彈出消息8應用程序。

回答

3

我不認爲這種類型的消息彈出窗口有隱藏/解僱/取消命令。按下鍵盤上的退出鍵時,調用取消命令。 Thees類型的消息不適用於信息目的。你應該改用「FlyOut」。

HTML:

<!-- Define a flyout in HTML as you wish --> 
<div id="informationFlyout" data-win-control="WinJS.UI.Flyout"> 
    <p> 
     Some informative text 
    </p> 
</div> 

<!-- an anchor for the flyout, where it should be displayed --> 
<div id="flyoutAnchor"></div> 

JS:

// Get an anchor for the flyout 
    var flyoutAnchor = document.getElementById("flyoutAnchor"); 

    // Show flyout at anchor 
    document.getElementById("informationFlyout").winControl.show(flyoutAnchor); 

要消除設定的時間量後彈出,你可以只是做一個setTimeout和隱藏在你的代碼:

// execute this code after 2000ms 
setTimeout(function() { 

    // Fetch the flyout 
    var flyout = document.getElementById("informationFlyout"); // Get the flyout from HTML 

    // Check if the element still exists in DOM 
    if (flyout) 
     flyout.winControl.hide(); // Dismiss the flyout 

}, 2000); 

閱讀更多有關彈出,彈出窗口here

+0

這是錯誤的,因爲事實上有一個取消。在下面檢查我的答案。 – 2014-01-28 10:38:11

1

有INFACT取消,你可以調用由showAsync方法返回的對象上,首先調用messageDialog這樣:

var msg = new Windows.UI.Popups.MessageDialog("No internet connection has been found."); 
var asyncOperation = msg.showAsync(); 

那麼每當你想要的你可以撥打電話:

asyncOperation.cancel(); 

and messageDialog will be dismissed。