Phantomjs-onprompt

提供:Dev Guides
移動先:案内検索

PhantomJS-onPrompt()

このコールバックは、Webページによってプロンプトが呼び出されたときに呼び出されます。 messageanswer の2つの引数を取ります。 戻り値は文字列です。

構文

その構文は次のとおりです-

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('http://localhost/tasks/promptl', function(status) {
   console.log(status);
});

早速

<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>

上記のプログラムは、次の output を生成します。

Entering in onPrompt callback
Is the page loaded
Success