I'm using a ContentPlaceHolder and would like to move the onload="Carousel()" from the body tag of of the .master page
body onload="Carousel()"
but I don't know where to put it in the content page.
I'm trying to implement this
I'm using a ContentPlaceHolder and would like to move the onload="Carousel()" from the body tag of of the .master page
body onload="Carousel()"
but I don't know where to put it in the content page.
I'm trying to implement this
It may be overkill, but if you have access to the jQuery javascript library on the page, the following javascript can be put on your content page:
$(document).ready(function() {
Carousel();
});
The reason why it's currently on
<body onload="...
is because the script needs to run after the document has been loaded in to the browser. At that time the DOM has finished loading and you have access to all of your elements.
You have two options:
Place the call to Carosel() as far towards the bottom of the page as you can go. By doing this the script won't be run until the rest of the page has loaded (loads from top to bottom).
or
handle the body onload event
<script type="text/javascript">
body.onload = Carosel;
</script>
You could also use jQuery:
<script type="text/javascript">
$(document).ready(Carosel);
</script>