# Execute javascript code when page is loaded

**URL:** <https://community.developer.atlassian.com/t/execute-javascript-code-when-page-is-loaded/2056>\
**Category:** Jira Server\
**Tags:** javascript, jira, jira-server\
**Created:** [April 5, 2017, 2:01pm UTC](https://community.developer.atlassian.com/t/execute-javascript-code-when-page-is-loaded/2056 "2017-04-05T14:01:52Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![yvesriel](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/yvesriel/32/310_2.png) [@yvesriel](https://community.developer.atlassian.com/u/yvesriel)\
**Post date:** [April 5, 2017, 2:19pm UTC](https://community.developer.atlassian.com/t/execute-javascript-code-when-page-is-loaded/2056/2 "2017-04-05T14:19:42Z")

</div>

In your javascript, inject the ‘jira/util/events’ module and bind to NEW\_CONTENT\_ADDED with the reason ‘pageLoaded’. That’s how I do it.

```auto
require([
		'jira/util/events',
	  	'jira/util/events/types',
	  	'jira/util/events/reasons'
 	 ], function(Events, EventTypes, EventReasons) {

	"use strict";
	
    Events.bind(EventTypes.NEW_CONTENT_ADDED, function(e, jiraContext, reason) {
        // Do your stuff here but check for the reason first to avoid being called too often
    });

```

---

_[View the full topic](https://community.developer.atlassian.com/t/execute-javascript-code-when-page-is-loaded/2056)._
