I have an HTML page which contains some clickable elements. I do not control the source of the page (think of my code as a browser extension). These elements are both buttons and divs. I would like to trigger the click programmatically when the user enters the page. Something like this:
function auto_click(some_div) {
// do some other stuff
some_div.click();
}
This function works, insofar as it executes a click event and successfully clicks the elements. However some of these elements are supposed to open a new page in another tab. While I can use the javascript DOM.click()
function, the result is a redirection a browser redirection following a pop-up message within the current tab, rather than opening a new tab.
When I click the element on the page manually, it successfully opens the content in a new tab.
My Question:
Why can't I use the DOM.click()
method to execute this in the same way as if I were clicking manually? Is there some other programmatic approach which would work?
Here is a fiddle illustrating my dilemma. I have commented out the auto-click code so you can view the difference yourself: