[英]How do you do an alert / message / popup box using JScript on Windows?
我正在嘗試在Windows 10上發出 Window alert
,但進展並不順利。
這是我嘗試過的:
window.alert("Alert");
和
alert("Alert");
如果它也是另一種語言也沒關系。 但是如果JavaScript中有辦法做到,請回答!
alert("Alert");
應該管用。
你可以在這里測試它: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_alert
我剛剛做了,在win 10上,它工作正常。
window.alert
僅是瀏覽器 function。 您只能在瀏覽器環境中執行它。
對於 WSH JScript 中的簡單消息框,請編寫:
WScript.Echo("Windows message box sample");
如果您需要 WSH JScript 中的擴展消息框,請編寫:
var mbOK = 0,
mbOKCancel = 1,
mbCancel = 2,
mbInformation = 64, // Information icon
text = //"Windows Script Host sample",
title = //"Title sample",
wshShell = WScript.CreateObject("WScript.Shell"),
intDoIt = wshShell.Popup(text,
0, //if > 0, seconds to show popup. With 0 it is without timeout.
title,
mbOKCancel + mbInformation);
if(intDoIt == mbCancel)
{
WScript.Quit(); //End of WScript (every for & while loops end too)
}
WScript.Echo("Sample executed");
您必須將所有內容保存在example.js
文件中並通過鼠標雙擊執行該文件。 如果您需要支持國際消息,請將其保存為unicode格式(但不是UTF-8 格式。)。
如果您每 15 秒(或可能 1 小時)需要一些消息框,您可以使用while
循環和WScript.sleep
function 來完成,因為我們在 WSH JScript 中也沒有setTimeout
function。
在下一個代碼示例中,如果您一直單擊“確定”按鈕,我們會在無限循環中每 15 秒出現一個消息框。 單擊取消按鈕將結束整個腳本(每個 for & while 循環也結束)。
while(true)
{
var mbOK = 0,
mbOKCancel = 1,
mbCancel = 2,
mbInformation = 64, // Information icon
text = "TO-DO: Write your App code! Do It! Just Do It!",
title = "Simple TO-DO thing",
wshShell = WScript.CreateObject("WScript.Shell"),
intDoIt = wshShell.Popup(text,
0, //if > 0, seconds to show popup. With 0 it is without timeout.
title,
mbOKCancel + mbInformation);
if(intDoIt == mbCancel)
{
WScript.Quit(); //End of WScript (every for & while loops end too)
}
WScript.sleep(15000); //Every 15 seconds. And 60*60*1000=3600000 for every hour
}
您將在Microsoft Windows Script Host 2.0 開發人員指南在線圖書中獲得更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.