I am using sitemesh in our application. In decorator jsp I have added <decorator:head>
in head and on body tag:
<body onload="<decorator:getProperty property='body.onload'/>" >
So I want to handle body onload
on my jsp page.
I have added following things:
<script type="text/javascript">
function init() {
alert("hi");
}
</script>
</head>
<body onload="javascript:init();">
But init()
does not worked in my jsp page.
<body onLoad=””>. In HTML Attributes. 0 Shares. The onLoad attribute is an event handler that instructs the browser to run a script when the visitor loads the page. This is commonly used to forward the visitor to another page, but can be used to trigger pop-up boxes, or execute a script based on the user's browser version.
To handle the load event, you register an event listener using the addEventListener () method: window.addEventListener ('load', (event) => { console.log ('The page has fully loaded'); }); Code language: JavaScript (javascript) Or using the onload property of the window object:
Or using the onload property of the window object: If you maintain a legacy system, you may find that the load event handler is registered in of the body element of the HTML document, like this: It’s a good practice to use the addEventListener () method to assign the onload event handler whenever possible.
This is commonly used to forward the visitor to another page, but can be used to trigger pop-up boxes, or execute a script based on the user’s browser version. body event handlers act on the browser window, and the script will only be executed once the page is completely finished loading.
Why not just stick it all into the script
element? Much cleaner than mucking about with element attributes:
window.onload = function() {
alert('hi');
};
Or, alternatively, keeping the init
declaration:
window.onload = init;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With