chrome拡張にてchrome.scripting.executeScriptをつかってWEBページ内のリストボックスの値を書き換えました。
しかしユーザー操作でリストボックスの選択を行うとリストボックスのonchangeが実行されるのですが
chrome拡張からvalueの値を直接書き換えるとonchangeが実行されません。
そこで値の書き換え後
window.frames[0].document.getElementById("ID名").onchange();
と記述してonchangeの実行を試みましたが
Uncaught TypeError: window.frames[0].document.getElementById(...).onchange is not a function
このようにこんな関数はないとエラーがでてしまいました。
上記をWEBページ内のコンソールで実行するとうまくいきました。
chrome拡張からOnchangeを実行する方法をご存じの方ご教授いただけないでしょうか。
お手数おかけしますがよろしくお願いします。
以下がWEBページ内のリストボックスのHTMLと拡張のソースです
HTML
1<select name="name" id="ID" tabindex="11" size="1" class="BOX" style="width:150px; " onchange="add_2(this);submit_win2(this.form,this.id);" onkeydown="if ((LoaderInPs == 'function') && isLoaderInPs() && pt2!=null) { pt2.terminateEvent(event); } ">
JavaScript
1function nameOutput(textname){ 2 3 window.frames[0].document.getElementById("ID").value = textname ; 4window.frames[0].document.getElementById("ID").onchange(); 5} 6 7document.getElementById('form').onsubmit =function () { 8 let textname = document.forms[0].elements[0].value; 9 chrome.tabs.sendMessage(tabs[0].id, send_data); 10 11 chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { 12 chrome.scripting.executeScript({ 13 target: {tabId: tabs[0].id}, 14 function:nameOutput, 15 args: [textname] 16 }); 17 }); 18}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/17 23:59
2022/05/18 00:18
2022/05/18 12:52