\" \r\nhtml = html + \" \" \r\nhtml = html + \" \"\r\n\r\nGuiIE.Document.Body.InnerHtml = html\r\nGuiIE.Document.Title = \"VBScript GUI test.\"\r\nwscript.echo html\r\n' ボタンがクリックされるまで待つ\r\non error resume next\r\n\r\nfunction is_clicked(GuiIE)\r\n is_clicked = GuiIE.Document.GetElementsByName(\"CLICKED\")(0).value <> \"false\"\r\nend function\r\ndo while GuiIE.Busy or not is_clicked(GuiIE)\r\n if Err.Number <> 0 then exit do\r\n w.sleep 100\r\nloop\r\n\r\n' 入力されたユーザー名とパスワードを表示\r\nif Err.Number = 0 then\r\n userid = GuiIE.Document.GetElementsByName(\"USERID\")(0).value\r\n passwd = GuiIE.Document.GetElementsByName(\"PASSWD\")(0).value\r\n GuiIE.Quit\r\n \r\n w.echo \"Your input userid and password\" + vbcrlf + vbcrlf _\r\n + \"userid: \" + userid + vbcrlf _\r\n + \"passwd: \" + passwd\r\nend if\r\n```\r\n\r\n回答者の方のアドバイスにより\r\n以下のように したのですが\r\n動作しません (再度修正)\r\n\r\n```vbs\r\n\r\nscr = scr + \" var createSelectBox = function (){ \" \r\nscr = scr + \" var arr = [ \" \r\nscr = scr + \" {val:'01', txt:'ポチ'}, \" \r\nscr = scr + \" {val:'02', txt:'タマ'}, \" \r\nscr = scr + \" {val:'03', txt:'モモ'} \" \r\nscr = scr + \" ]; \" \r\nscr = scr + \" for(var i=0;i \" \r\nhtml = html + \" \" \r\nhtml = html + \" User ID:
\" \r\nhtml = html + \" Password:
\" \r\nhtml = html + \" \" \r\nhtml = html + \" \" \r\nhtml = html + \" \" \r\nhtml = html + \" \"\r\nwscript.echo scr\r\nGuiIE.Document.Body.InnerHtml = html\r\nscript = GuiIE.Document.createElement(\"script\")\r\nscript.innerHTML = scr\r\nGuiIE.Document.Body.appendChild(script)\r\nGuiIE.Document.Title = \"VBScript GUI test.\"\r\nwscript.echo html\r\n' ボタンがクリックされるまで待つ\r\non error resume next\r\n\r\n```","answerCount":1,"upvoteCount":0,"datePublished":"2019-09-08T05:56:10.758Z","dateModified":"2019-09-08T11:10:22.235Z","acceptedAnswer":{"@type":"Answer","text":"JavaScriptを除いたHTMLを突っ込んだ後で、VBSで`createElement(\"script\")`して、そこにスクリプトを入れて`body`にappendChild`してください。\r\n\r\n`option`の作成自体をVBSでやってもいいのでは?","dateModified":"2019-09-08T09:41:43.657Z","datePublished":"2019-09-08T09:41:43.657Z","upvoteCount":1,"url":"https://teratail.com/questions/210758#reply-310749"},"suggestedAnswer":[],"breadcrumb":{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https://teratail.com","name":"トップ"}},{"@type":"ListItem","position":2,"item":{"@id":"https://teratail.com/tags/Internet%20Explorer","name":"Internet Explorerに関する質問"}},{"@type":"ListItem","position":3,"item":{"@id":"https://teratail.com/questions/210758","name":"再修正【Javascript】【vbs】実行されない?"}}]}}}
質問するログイン新規登録

Q&A

解決済

1回答

1495閲覧

再修正【Javascript】【vbs】実行されない?

Reach

総合スコア735

Internet Explorer

Internet Explorer(IE;MSIE)はマイクロソフトが開発したウェブブラウザです。Microsoft Windowsに組み込まれています。

VBScript

VBScript(Visual Basic Scripting Edition)はMicrosftが開発したスクリプト言語であり、Visual Basicのサブセットです。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2019/09/08 05:56

編集2019/09/08 11:10

0

0

お世話になります

以下のVBScriptを実行しても
Javascriptが 機能していないみたいなのですが
htmlの内容を .htmlファイルにして IEに D&Dして "ボタン"を押下すると
動作します (aleat表示、アイテム追加)

何がいけないのでしょうか?

よろしく お願いいたします。

vbs

1set w = WScript 2 3set GuiIE = CreateObject("InternetExplorer.Application") 4GuiIE.Width = 300 5GuiIE.Height = 450 6GuiIE.ToolBar = false 7GuiIE.StatusBar = false 8GuiIE.Resizable = false 9GuiIE.Visible = true 10GuiIE.Navigate "about:blank" 11do while GuiIE.Busy 12 w.sleep 100 13loop 14 15' ユーザーIDとパスワードの入力ボックスと、ボタンを表示 16html = "" 17html = html + " <form> " 18html = html + " <input type='hidden' name='CLICKED' value='false'/> " 19html = html + " User ID: <input type='text' name='USERID'/> </br>" 20html = html + " Password: <input type='password' name='PASSWD'/></br> " 21html = html + " <select id='sel1'></select> " 22html = html + " <input type='button' value= 'ボタン' onclick='createSelectBox();' /> " 23html = html + " <script type='text/javascript'> " 24html = html + " var createSelectBox = function (){ " 25html = html + " var arr = [ " 26html = html + " {val:'01', txt:'ポチ'}, " 27html = html + " {val:'02', txt:'タマ'}, " 28html = html + " {val:'03', txt:'モモ'} " 29html = html + " ]; " 30html = html + " for(var i=0;i<arr.length;i++){ " 31html = html + " alert(arr[i].txt); " 32html = html + " } " 33html = html + " for(var i=0;i<arr.length;i++){ " 34html = html + " op = document.createElement('option'); " 35html = html + " op.value = arr[i].val; " 36html = html + " op.innerText = arr[i].txt; " 37html = html + " document.getElementById('sel1').appendChild(op); " 38html = html + " console.log(arr[i].txt); " 39html = html + " } " 40html = html + " }; " 41html = html + " </script> " 42html = html + " <input type='button' " 43html = html + " onClick = ""getElementsByName('CLICKED')(0).value = 'true';"" " 44html = html + " value='OK' /> " 45html = html + " </form> " 46 47GuiIE.Document.Body.InnerHtml = html 48GuiIE.Document.Title = "VBScript GUI test." 49wscript.echo html 50' ボタンがクリックされるまで待つ 51on error resume next 52 53function is_clicked(GuiIE) 54 is_clicked = GuiIE.Document.GetElementsByName("CLICKED")(0).value <> "false" 55end function 56do while GuiIE.Busy or not is_clicked(GuiIE) 57 if Err.Number <> 0 then exit do 58 w.sleep 100 59loop 60 61' 入力されたユーザー名とパスワードを表示 62if Err.Number = 0 then 63 userid = GuiIE.Document.GetElementsByName("USERID")(0).value 64 passwd = GuiIE.Document.GetElementsByName("PASSWD")(0).value 65 GuiIE.Quit 66 67 w.echo "Your input userid and password" + vbcrlf + vbcrlf _ 68 + "userid: " + userid + vbcrlf _ 69 + "passwd: " + passwd 70end if

回答者の方のアドバイスにより
以下のように したのですが
動作しません (再度修正)

vbs

1 2scr = scr + " var createSelectBox = function (){ " 3scr = scr + " var arr = [ " 4scr = scr + " {val:'01', txt:'ポチ'}, " 5scr = scr + " {val:'02', txt:'タマ'}, " 6scr = scr + " {val:'03', txt:'モモ'} " 7scr = scr + " ]; " 8scr = scr + " for(var i=0;i<arr.length;i++){ " 9scr = scr + " alert(arr[i].txt); " 10scr = scr + " } " 11scr = scr + " for(var i=0;i<arr.length;i++){ " 12scr = scr + " op = document.createElement('option'); " 13scr = scr + " op.value = arr[i].val; " 14scr = scr + " op.innerText = arr[i].txt; " 15scr = scr + " document.getElementById('sel1').appendChild(op); " 16scr = scr + " } " 17scr = scr + " }; " 18 19' ユーザーIDとパスワードの入力ボックスと、ボタンを表示 20html = "" 21html = html + " <form> " 22html = html + " <input type='hidden' name='CLICKED' value='false'/> " 23html = html + " User ID: <input type='text' name='USERID'/> </br>" 24html = html + " Password: <input type='password' name='PASSWD'/></br> " 25html = html + " <select id='sel1'></select> " 26html = html + " <input type='button' value= 'ボタン' onclick='createSelectBox();' /> " 27html = html + " <input type='button' onClick = ""getElementsByName('CLICKED')(0).value = 'true';"" value='OK' /> " 28html = html + " </form> " 29wscript.echo scr 30GuiIE.Document.Body.InnerHtml = html 31script = GuiIE.Document.createElement("script") 32script.innerHTML = scr 33GuiIE.Document.Body.appendChild(script) 34GuiIE.Document.Title = "VBScript GUI test." 35wscript.echo html 36' ボタンがクリックされるまで待つ 37on error resume next 38

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2019/09/08 05:58

すみません。動作するのしますというのはどういうことでしょうか?
退会済みユーザー

退会済みユーザー

2019/09/08 06:05

編集ありがとうございますm(_ _)m
guest

回答1

0

ベストアンサー

JavaScriptを除いたHTMLを突っ込んだ後で、VBSでcreateElement("script")して、そこにスクリプトを入れてbodyにappendChild`してください。

optionの作成自体をVBSでやってもいいのでは?

投稿2019/09/08 09:41

otn

総合スコア86461

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Reach

2019/09/08 10:36

ご回答ありがとうございます 一部修正したのですが 上手くいきません Javascript 超初心者なので ‥‥
otn

2019/09/08 10:48

変数 scr に、<script>タグは不要です。JavaScript部分のみ書いてください。 (innerHTMLとouterHTMLの違い)
Reach

2019/09/08 11:09

<script>タグを 削除して 実行しても 駄目でした どこが いけないのでしょうか?
otn

2019/09/08 11:15

script = GuiIE.Document.createElement("script") ↓ set script = GuiIE.Document.createElement("script") オブジェクトの代入にはsetが必要です。 次の行で、エラーメッセージが出てたはず。
Reach

2019/09/08 11:18

上手くいきました!! ありがとうございます!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.29%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問