I have a page where I have a function in window.onload to simulate a click on an element. This click can only happen when the page is completely loaded. It turns out that the function works when you first go to the page. After that it stops working. Close the function even without some elements on the screen.
Here is my simple function:
function clickOnMarker(){
alert('click on marker');
var markerName = jQuery(".entry-title").text();
jQuery( 'div[title="' + markerName + '"]' ).trigger( 'click' );
alert('Fez clique no marker');
}
window.onload = function() {
clickOnMarker();
};
The function reads the value of a title and clicks on a marker (HeroMap plugin - WordPress) to focus. It turns out that after running the sequences once, the function runs even without having the markers on the map.
Is there a way to control this behavior and always ensure that the script only runs if the markers are on the page? From what I saw, window.onload has this behavior and therefore my plan is ruined :).
Thank you for your help.
I ended up finding a solution a little out of the box :).
It worked and is what it takes :)