MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / open

Method open

src/main/java/org/htmlunit/javascript/host/Window.java:406–455  ·  view source on GitHub ↗

Opens a new window. @param url when a new document is opened, url is a String that specifies a MIME type for the document. When a new window is opened, url is a String that specifies the URL to render in the new window @param name the name @param features the features @param re

(final Object url, final Object name, final Object features,
            final Object replace)

Source from the content-addressed store, hash-verified

404 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536651.aspx">MSDN documentation</a>
405 */
406 @JsxFunction
407 public WindowProxy open(final Object url, final Object name, final Object features,
408 final Object replace) {
409 String urlString = null;
410 if (!JavaScriptEngine.isUndefined(url)) {
411 urlString = JavaScriptEngine.toString(url);
412 }
413 String windowName = "";
414 if (!JavaScriptEngine.isUndefined(name)) {
415 windowName = JavaScriptEngine.toString(name);
416 }
417 String featuresString = null;
418 if (!JavaScriptEngine.isUndefined(features)) {
419 featuresString = JavaScriptEngine.toString(features);
420 }
421 final WebClient webClient = getWebWindow().getWebClient();
422
423 if (webClient.getOptions().isPopupBlockerEnabled()) {
424 LOG.debug("Ignoring window.open() invocation because popups are blocked.");
425 return null;
426 }
427
428 boolean replaceCurrentEntryInBrowsingHistory = false;
429 if (!JavaScriptEngine.isUndefined(replace)) {
430 replaceCurrentEntryInBrowsingHistory = JavaScriptEngine.toBoolean(replace);
431 }
432 if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) {
433 LOG.debug(
434 "window.open: features and replaceCurrentEntryInBrowsingHistory "
435 + "not implemented: url=[" + urlString
436 + "] windowName=[" + windowName
437 + "] features=[" + featuresString
438 + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory
439 + "]");
440 }
441
442 // if specified name is the name of an existing window, then hold it
443 if (StringUtils.isEmptyOrNull(urlString) && !StringUtils.isEmptyString(windowName)) {
444 try {
445 final WebWindow webWindow = webClient.getWebWindowByName(windowName);
446 return getProxy(webWindow);
447 }
448 catch (final WebWindowNotFoundException ignored) {
449 // nothing
450 }
451 }
452 final URL newUrl = makeUrlForOpenWindow(urlString);
453 final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_);
454 return getProxy(newWebWindow);
455 }
456
457 private URL makeUrlForOpenWindow(final String urlString) {
458 if (urlString.isEmpty()) {

Callers

nothing calls this directly

Calls 15

isUndefinedMethod · 0.95
toStringMethod · 0.95
getWebWindowMethod · 0.95
getOptionsMethod · 0.95
toBooleanMethod · 0.95
isEmptyOrNullMethod · 0.95
isEmptyStringMethod · 0.95
getWebWindowByNameMethod · 0.95
getProxyMethod · 0.95
makeUrlForOpenWindowMethod · 0.95
openWindowMethod · 0.95
isPopupBlockerEnabledMethod · 0.80

Tested by

no test coverage detected