javascriptjspsitemesh

How to handle body onload event in <head> tag


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.


Solution

  • try this

    <script type="text/javascript">
        function init() {
            alert("hi");
        }
    </script>
    </head>
    <body onload="init();">