LoginSignup
2
1

More than 5 years have passed since last update.

元ページ側の onchange を発火できなくてハマったのでメモ

Last updated at Posted at 2018-10-03
original.html
<select name="hoge" onchange="fuga()">
</select>

(jQUeryで)うまいことfuga関数をChromeExtensionから発火させたい。

contentscript.js
//こういった書き方では実行できない。
$('select[name=hoge]').change();

セキュリティ的には当然。
じゃあどうするか。

contentscript.js
//ダミーボタン作って
var tag = '<button type="button" id="myDummyButton" style="display: none;" onclick="fuga()">';

//追加して
$('form[name=piyo]').append(tag);

//発火
$('#myDummyButton').click();

うごいちゃうけどこれいいの?

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1