Jump to content

Javascript in Footer executing in 3 Times


Recommended Posts

Hi There,

I'm using a Chart Datapage and in the search footer I have the following which i'm testing something weird.

<script>
document.addEventListener('DataPageReady', function (event) {
alert("Hello World");
});
</script>

The hello world executes 3 times upon loading..

Can someone advise i I would be able to limit the execution to run just once?

Link to comment
Share on other sites

Hi @Elderberg

This is not related to cache or cookies. This is the default behavior of "DataPageReady" event.
You need to clean this event after executing. Also, you need to define functions out of event listener to increase the performance.

Here is the example of the code: 
 

<script>
function someFunc() {
	alert("Hello World");
	document.removeEventListener("DataPageReady", someFunc);
}

document.addEventListener('DataPageReady', someFunc);
</script>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...