Page 1 of 1
How to add onload=
Posted: Sat Feb 03, 2018 12:50 pm
by GrahamW
I have a javascript I wrote that pre loads images and I need to add this into my extension
How can I get it to add the onload="preLoad()" part in the script directly after the opening body tag
Graham
Re: How to add onload=
Posted: Sat Feb 03, 2018 2:05 pm
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>
Re: How to add onload=
Posted: Sat Feb 03, 2018 2:11 pm
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>