com.gargoylesoftware.htmlunit.OnbeforeunloadHandler Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.OnbeforeunloadHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtmlPage.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private boolean isOnbeforeunloadAccepted(final HtmlPage page, final Event event) {
    if (event instanceof BeforeUnloadEvent) {
        final BeforeUnloadEvent beforeUnloadEvent = (BeforeUnloadEvent) event;
        if (beforeUnloadEvent.isBeforeUnloadMessageSet()) {
            final OnbeforeunloadHandler handler = getWebClient().getOnbeforeunloadHandler();
            if (handler == null) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn("document.onbeforeunload() returned a string in event.returnValue,"
                            + " but no onbeforeunload handler installed.");
                }
            }
            else {
                final String message = Context.toString(beforeUnloadEvent.getReturnValue());
                return handler.handleEvent(page, message);
            }
        }
    }
    return true;
}
 
Example #2
Source File: HtmlPage.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private boolean isOnbeforeunloadAccepted(final HtmlPage page, final Event event, final ScriptResult result) {
    if (event.getType().equals(Event.TYPE_BEFORE_UNLOAD)) {
        final boolean ie = hasFeature(JS_CALL_RESULT_IS_LAST_RETURN_VALUE);
        final String message = getBeforeUnloadMessage(event, result, ie);
        if (message != null) {
            final OnbeforeunloadHandler handler = getWebClient().getOnbeforeunloadHandler();
            if (handler == null) {
                LOG.warn("document.onbeforeunload() returned a string in event.returnValue,"
                        + " but no onbeforeunload handler installed.");
            }
            else {
                return handler.handleEvent(page, message);
            }
        }
    }
    return true;
}