- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他內容
- 命令列介面
- PhantomJS - 螢幕截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用的資源
- PhantomJS - 討論
PhantomJS - onPrompt()
當網頁呼叫提示時,將呼叫此回撥。它需要兩個引數,message 和 answer。返回值是字串。
語法
其語法如下 -
wpage.onPrompt = function(msg, defaultVal) {}
示例
以下程式碼顯示了 onPrompt() 方法的使用。
var wpage = require('webpage').create();
wpage.onPrompt = function(msg, answer) {
console.log("Entering in onPrompt callback");
console.log(msg);
return answer;
}
wpage.open('https:///tasks/prompt.html', function(status) {
console.log(status);
});
prompt.html
<html>
<head>
<title>Welcome to phantomjs</title>
</head>
<body>
<script type = "text/javascript">
window.onload = function() {
prompt("Is the page loaded", "");
}
</script>
<h1>This is a test page</h1>
</body>
</html>
以上程式生成以下輸出。
Entering in onPrompt callback Is the page loaded Success
phantomjs_webpage_module_events_callbacks.htm
廣告