最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - flutter_inappwebview windows desktop cannot trigger evaluateJavascript mouse focus by code to document.getElementBy

programmeradmin7浏览0评论

I want to trigger evaluateJavascript mouse focus by code to document.getElementById('txt_amount'), but it's not working on Windows Desktop. But it's working well on MacOS. When page loaded, I want it to trigger document.getElementById('txt_amount') by mouseFocusEvent, removeAttribute('required') and filled with amountValue2.value = 100 and then click button2 by document.querySelector('button').click() and submit button Continue automatically, But it's not working on Windows Desktop(it's working very well on MacOS).

var amountValue2 = document.getElementById('txt_amount');
                if (amountValue2) {
                    amountValue2.value = 100;
                } else {
                    console.log('amountValue2 not founded.');
                }

                let button2 = document.querySelector('button');
                if (button2) {
                     button2.disabled = false;
                     button2.addEventListener('click', function() {
                       });
                    var mouseFocusEvent = new MouseEvent('focus', {
                    bubbles: true,  // Allow event to bubble up the DOM tree
                    cancelable: true, // Allow the event to be canceled
                    view: window, // Specify the window object
                    clientX: 0, // Mouse position relative to the viewport
                    clientY: 0 // Mouse position relative to the viewport
                  });
                  amountValue2.addEventListener('focus', function() {
                  amountValue2.value = $amount;
                        console.log('Mouse 1 focus!');
                      });

                  window.setTimeout(() => {
                  amountValue2.removeAttribute('required');
                  amountValue2.dispatchEvent(mouseFocusEvent);
                  button2.focus();
                  button2.click();
                }, 500);
                } else {
                    console.log('Button not founded.');
                }

Image show below

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论