This seems so simple, yet I cannot find an example of how to call javascript function from wicket, after the page is loaded (on page that extends WebPage). Can anyone give example on how to go that?
You can have javascript do that for you
window.onload = function () {
// do stuff here
}
If you need parameters from your wicket page in the javascript function you can override renderHead and add the function there:
@Override
public void renderHead(IHeaderResponse response)
{
super.renderHead(response);
String bar = "something";
response.render(JavaScriptHeaderItem.forScript("window.onload = function () {var foo='" + bar + "'}"));
// or
response.render(OnDomReadyHeaderItem.forScript("functionToCall(" + bar + ");") ;
}
Yet another way to do that is to create AjaxEventBehavior as follows and add it to your page.
AjaxEventBehavior event = new AjaxEventBehavior("onload") {
@Override
protected void onEvent(final AjaxRequestTarget target) {
// do stuff here
target.appendJavaScript("alert('onload');");
}
}
add(event);
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