- PhantomJST 教程
- PhantomJS - 首頁
- PhantomJS - 概覽
- PhantomJS - 環境設定
- PhantomJS - 物件
- PhantomJS - 方法
- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 服務模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 螢幕截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
PhantomJS - onAlert()
當頁面上有提示時,將呼叫此回撥。該回調採用一個字串,不會返回任何內容。
語法
其語法如下:
var wpage = require('webpage').create();
wpage.onAlert = function(msg) {};
示例
以下示例展示瞭如何使用 onAlert() 方法。
var wpage = require('webpage').create();
wpage.onAlert = function(str) {
console.log(str);
}
wpage.open('https:///tasks/alert.html', function(status) {
//wpage.stop();
console.log(status);
phantom.exit();
});
alert.html
<html>
<head></head>
<body>
<script type = "text/javascript">
alert("Welcome to phantomjs");
</script>
<h1>This is a test page</h1>
</body>
</html>
上述程式生成了以下 輸出。
Welcome to phantomjs Success
phantomjs_webpage_module_events_callbacks.htm
廣告