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: 238
Joined: Sat Jul 08, 2017 5:02 am

How to add onload=

Post by GrahamW »

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: 22489
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: How to add onload=

Post by Pablo »

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: 5648
Joined: Thu Aug 16, 2007 7:32 pm

Re: How to add onload=

Post by BaconFries »

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