Java Code Examples for com.gargoylesoftware.htmlunit.WebClient#openWindow()
The following examples show how to use
com.gargoylesoftware.htmlunit.WebClient#openWindow() .
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: Window.java From htmlunit with Apache License 2.0 | 4 votes |
/** * Opens a new window. * * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document. * When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window * @param name the name * @param features the features * @param replace whether to replace in the history list or no * @return the newly opened window, or {@code null} if popup windows have been disabled * @see com.gargoylesoftware.htmlunit.WebClientOptions#isPopupBlockerEnabled() * @see <a href="http://msdn.microsoft.com/en-us/library/ms536651.aspx">MSDN documentation</a> */ @JsxFunction public WindowProxy open(final Object url, final Object name, final Object features, final Object replace) { String urlString = null; if (!Undefined.isUndefined(url)) { urlString = Context.toString(url); } String windowName = ""; if (!Undefined.isUndefined(name)) { windowName = Context.toString(name); } String featuresString = null; if (!Undefined.isUndefined(features)) { featuresString = Context.toString(features); } final WebClient webClient = getWebWindow().getWebClient(); if (webClient.getOptions().isPopupBlockerEnabled()) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring window.open() invocation because popups are blocked."); } return null; } boolean replaceCurrentEntryInBrowsingHistory = false; if (!Undefined.isUndefined(replace)) { replaceCurrentEntryInBrowsingHistory = Context.toBoolean(replace); } if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) { LOG.debug( "window.open: features and replaceCurrentEntryInBrowsingHistory " + "not implemented: url=[" + urlString + "] windowName=[" + windowName + "] features=[" + featuresString + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory + "]"); } // if specified name is the name of an existing window, then hold it if (StringUtils.isEmpty(urlString) && !"".equals(windowName)) { try { final WebWindow webWindow = webClient.getWebWindowByName(windowName); return getProxy(webWindow); } catch (final WebWindowNotFoundException e) { // nothing } } final URL newUrl = makeUrlForOpenWindow(urlString); final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_); return getProxy(newWebWindow); }
Example 2
Source File: Window.java From HtmlUnit-Android with Apache License 2.0 | 4 votes |
/** * Opens a new window. * * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document. * When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window * @param name the name * @param features the features * @param replace whether to replace in the history list or no * @return the newly opened window, or {@code null} if popup windows have been disabled * @see com.gargoylesoftware.htmlunit.WebClientOptions#isPopupBlockerEnabled() * @see <a href="http://msdn.microsoft.com/en-us/library/ms536651.aspx">MSDN documentation</a> */ @JsxFunction public WindowProxy open(final Object url, final Object name, final Object features, final Object replace) { String urlString = null; if (url != Undefined.instance) { urlString = Context.toString(url); } String windowName = ""; if (name != Undefined.instance) { windowName = Context.toString(name); } String featuresString = null; if (features != Undefined.instance) { featuresString = Context.toString(features); } final WebClient webClient = getWebWindow().getWebClient(); if (webClient.getOptions().isPopupBlockerEnabled()) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring window.open() invocation because popups are blocked."); } return null; } boolean replaceCurrentEntryInBrowsingHistory = false; if (replace != Undefined.instance) { replaceCurrentEntryInBrowsingHistory = Context.toBoolean(replace); } if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) { LOG.debug( "window.open: features and replaceCurrentEntryInBrowsingHistory " + "not implemented: url=[" + urlString + "] windowName=[" + windowName + "] features=[" + featuresString + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory + "]"); } // if specified name is the name of an existing window, then hold it if (StringUtils.isEmpty(urlString) && !"".equals(windowName)) { try { final WebWindow webWindow = webClient.getWebWindowByName(windowName); return getProxy(webWindow); } catch (final WebWindowNotFoundException e) { // nothing } } final URL newUrl = makeUrlForOpenWindow(urlString); final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_); return getProxy(newWebWindow); }