通常、Gmailの下書きは右上の×ボタンをマウスでクリックして「保存して閉じる」ことができますが、
それを今作っているChrome拡張機能内で自動で行いたいと思っています。
しかし、自分ではどうしても実現できず、
どうしたら自動で「保存して閉じる」(右上×ボタンをクリックさせる)ことができるのでしょうか。
元のHTML(×ボタン画像部分のみ)
html
1<img class="Ha" id=":yp" src="images/cleardot.gif" alt="閉じる" aria-label="保存して閉じる" data-tooltip-delay="800" data-tooltip="保存して閉じる">
試したこと⇒結果は全て反応なし
javascript
1$('.Ha').click(); 2 3$('.Ha').mousedown(); 4 5$('.Ha').dispatchEvent( new MouseEvent( "click" ) ); 6 7// 下書き内でEscapeキーを押下しても閉じることできるので、Escapeキー押下を試した(Elementは本文入力部分) 8document.getElementsByClassName('Am Al editable LW-avf tS-tW')[0].dispatchEvent( new KeyboardEvent ( "keydown", { keycode: 27 } ) ); 9 10// 手動でマウスクリックした時のイベント確認 11document.getElementsByClassName('Ha')[0].addEventListener( 'click', function(e) { console.log(e) } ); 12/* 結果⇒なぜimg#:yp.Ha.Hb? 13PointerEvent {isTrusted: true, pointerId: 2, width: 1, height: 1, pressure: 0, …} 14isTrusted: true 15altKey: false 16altitudeAngle: 1.5707963267948966 17azimuthAngle: 0 18bubbles: true 19button: 0 20buttons: 0 21cancelBubble: false 22cancelable: true 23clientX: 892 24clientY: 389 25composed: true 26ctrlKey: false 27currentTarget: null 28defaultPrevented: false 29detail: 1 30eventPhase: 0 31fromElement: null 32height: 1 33isPrimary: false 34layerX: 892 35layerY: 389 36metaKey: false 37movementX: 0 38movementY: 0 39offsetX: 892 40offsetY: 390 41pageX: 892 42pageY: 389 43path: (18) [img#:yp.Ha.Hb, td.Hm, tr#:ym, tbody, table.cf.Ht, div.nH.as2, div.aCk, div.k, div.l.n, div.l.m, div.nH, div.nH.Hy.aXJ, div.nH.Hd, div.nH, div.AD, div.nH.nn, div.no, div.nH] 44pointerId: 2 45pointerType: "touch" 46pressure: 0 47relatedTarget: null 48returnValue: true 49screenX: 740 50screenY: 452 51shiftKey: false 52sourceCapabilities: InputDeviceCapabilities {firesTouchEvents: true} 53srcElement: null 54tangentialPressure: 0 55target: null 56tiltX: 0 57tiltY: 0 58timeStamp: 68701.20000004768 59toElement: null 60twist: 0 61type: "click" 62view: Window {0: Window, 1: global, 2: global, 3: global, 4: global, 5: global, 6: global, 7: global, 8: global, 9: global, 10: global, 11: global, 12: Window, 13: Window, 14: Window, window: Window, self: Window, document: document, name: '', location: Location, …} 63which: 1 64width: 1 65x: 892 66y: 389 67[[Prototype]]: PointerEvent 68*/

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/03/02 03:51