How to add onload=

This section can be used to submit suggestions for Extension Builder.
Note that this section is not monitored for support.
Forum rules
This forum section can be used to submit suggestions for Extension Builder.
Note that this section is not monitored for support.
Post Reply
GrahamW
 
 
Posts: 195
Joined: Sat Jul 08, 2017 5:02 am

How to add onload=

Post by GrahamW » Sat Feb 03, 2018 12:50 pm

I have a javascript I wrote that pre loads images and I need to add this into my extension

Code: Select all

<body onload="preLoad()">
How can I get it to add the onload="preLoad()" part in the script directly after the opening body tag

Graham

User avatar
Pablo
 
Posts: 13039
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: How to add onload=

Post by Pablo » Sat Feb 03, 2018 2:05 pm

You cannot insert code directly inside the body tag with an extension.
However you can write your code like this:

Code: Select all

<script type="text/javascript">
      window.onload = function()
      {
          preLoad();
      };
</script>
or jQuery:

Code: Select all

<script type="text/javascript">
$(document).ready(function() // or $(function()
{
     preLoad();
 });
</script>

User avatar
BaconFries
 
 
Posts: 4006
Joined: Thu Aug 16, 2007 7:32 pm

Re: How to add onload=

Post by BaconFries » Sat Feb 03, 2018 2:11 pm

Just as Pablos second suggestion but using 'body'

Code: Select all

<script type="text/javascript">
$(document).ready(function () {
document.body.onload = function () 
}
 preLoad();
};
</script>

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests