There's a "Book Now" tab on a website. when you click it, it opens a form. I need to make the button open automatically if the URL is www.example.com/en/?emailer
. I tried this:
if (window.location.href == "http://www.example/en/?emailer") {
document.getElementsByClassName("tab")[0].click();
}
The thing is that if I paste this code on the page in the console, it works. However when I added it to the header.php WordPress file, it's not working.
Any idea why it works in the console and not in the <head>
? Can someone tell me how can I get this done?
Note: the tab has the class 'tab' as seen in the code section.
` tag, or in a document `load` event handler
– Rory McCrossan Aug 09 '18 at 07:53