Gravity forms causing scripts to run multiple times

Hi, I’m updating a client’s existing website for them. I’m afraid I have no previous experience with Gravity Forms, which they are using.

I have added a few lines of javascript for when the site menu is opened and closed. This is working on every page of their site except the two pages with Gravity Forms active on them.

On these pages, I have found, all scripts are being executed 4 times instantly. So when I click the menu button, it’s opening, closing, opening, closing instantly - giving the effect the button isn’t working at all.

I’ve checked this with other simple scripts too (just logging to the console), and the same thing occurs.

I’ve tried adding this script in my header, body, directly with the menu button. And this issue occurs each time. And only only the pages with Gravity Forms.

I’m sorry this is a little vague, but I’ve never seen anything like this before and have no idea what could be causing it. Specifically as 4 seems to be an arbitrary number of times to repeat it.

Any advice would be appreciated, thanks.

Can you share a link to the page on the website where we can see the form, and share the script with us and let us know how it is being added currently? Thank you.

Hi Chris

Sure, this is the particular page I’m having issues with -

For now, for testing purposes, I have actually removed the menu button and I’ve added 3 code snippets - one directly where the menu button appears in the header, one in the page’s head, one in the page’s body. These are all following this structure -

	console.log("head code");

When I load the page, I’m seeing each code execute 4 times in the console.

Interestingly, I have noticed in the console, they do appear to be coming from 4 different sources (see attached image), 3 of which seem to be related to virtual machines. But I’m not sure of the significance of that or what to do about it.

As mentioned before, I know this doesn’t seem to be connected to Gravity, but is only affecting the pages with Gravity Forms - if you navigate to the homepage of the above URL, you should see the codes only run once.

For anyone else having a similar issue in future, I haven’t got to to to the bottom of what’s causing it, but I have found a workaround by wrapping the code I want inside an if statement, along the lines of -

var check;

if ( check == null ) {
 // Code to be executed only once

check = "true";

I can see 4 versions of the script file are still loading, but the code I want is now only running once at least. It’s a bit of a hacky solution, and I’m not that happy with it, but it at least appears to have solved the problem for me.

From what I can tell, this definitely seems to be related to Virtual Machines in Chrome (at least based on what I can tell from developer tools). And may be something to do with caching too. I’m still none the wiser how it relates to Gravity Forms.

1 Like