<div class="webview">
<webview id="foo" src="http://xxxx/index.html" autosize="on"></webview>
</div>
<a href="http://www.baidu.com" target="_blank">_blank</a>I can reproduce this issue on Linux/Windows with nwjs-sdk-v0.21.6.
Steps:
src to http://127.0.0.1:8080/index.html).<!DOCTYPE html>
<html>
<body>
<a href="http://www.baidu.com" target="_blank">_blank</a>
</body>
</html>
Result:
target="_blank" --> Fail, no response
target="_self"-->Pass, open baidu page in the same frame
@rogerwang please assign it to me if you are not working on it.
@andy-huaan Chrome app also has the same result and error log:
"
: 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.
@xzhan96 we should provide a way to remove/control this limitation in NW app.
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>
@Christywl please double check my solution, and close the issue if it's ok.
@xzhan96 , your code works fine, it will open a new window.
this solution operating normally!
Most helpful comment
please refer to https://developer.chrome.com/apps/tags/webview#type-NewWindow/ and below code: