question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

when target="_blank" webview can not open url

See original GitHub issue
  1. version:nwjs-sdk-v0.21.5-win-x64
  2. webview page
<div class="webview">
	<webview id="foo" src="http://xxxx/index.html" autosize="on"></webview>
</div>
  1. http://xxxx/index.html page <a href="http://www.baidu.com" target="_blank">_blank</a> when target=“_blank”,webview cannot open url; when target=“_self” is ok Demo_20170413Z64_.zip

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
xzhan96commented, Apr 26, 2017

please refer to https://developer.chrome.com/apps/tags/webview#type-NewWindow/ and below code:

<script type="text/javascript">
function onNewWindow(event) {
  console.log("xiaofeng: ===================="+  event.windowOpenDisposition);

  switch (event.windowOpenDisposition) {
    case 'ignore':
      // Not sure what this is used by.  Default enum value, maybe.
      console.debug('Ignoring new window request');
      return;

    case 'save_to_disk':
      // Ctrl + S, maybe?  Not sure how to reproduce that.
      console.log('save_to_disk is not implemented');
      return;

    case 'current_tab':
      console.log("xiaofeng: ==================== current_tab");
      return;

    case 'new_background_tab':
    case 'new_foreground_tab':
      newWindow = open(event.targetUrl, '_blank');
      if (event.windowOpenDisposition != 'new_background_tab') {
        newWindow.focus();
      }
      break;

    case 'new_window':
    case 'new_popup':
      // if (event.initialWidth && event.initialHeight) {
      //   features = 'width=' + event.initialWidth + ',height=' + event.initialHeight;
      // }
      newWindow = open(event.targetUrl, '_blank');
      newWindow.focus();
      break;
  }
}

  window.onload = function() {
  var webview = document.getElementById('foo');
  console.log("+++++++++++++++++");
  webview.addEventListener('newwindow', onNewWindow);
};
</script>

1reaction
xzhan96commented, Apr 26, 2017

@andy-huaan Chrome app also has the same result and error log:

“<webview>: A new window was blocked.”, source: extensions::webViewActionRequests (84)

@Christywl I think it’s just the “webview” tag limitation instead of a bug. please refer to http://stackoverflow.com/questions/18428668/how-to-open-a-new-window-from-a-link-in-a-webview-in-a-chrome-packaged-app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Open target _blank links in WebView with external browser
If URL contains my website name, then I opened it in WebView and rest ... If you don't set the WebViewClient, I think...
Read more >
WebView doesnt open links with target blank : r/androiddev
I want that target blank urls open in the same webview! @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.
Read more >
[Bug] Cannot open URLs with WebView android when the ...
Description Cannot open URLs with WebView android when the target is _blank Steps to Reproduce Create a simple project with WebView.
Read more >
Open external browser on tapping on link with target=_blank ...
Webpage is getting loaded inside Xamarin forms webview, links with target="_blank" not working on android
Read more >
How to open target="_blank" links in WKWebView in iOS
Short post explaining why by default target _blank links don't do ... in this case) that this link should be open in new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found