JavaSheriff
JavaSheriff

Reputation: 7665

Chrome window.open shows Failed - Network error

I am using window.open to open a popup and display a result (PDF) this is working fine with IE/fire fox and the same used to work fine with chrome until not so long ago.

here is a live example, codepen editor seems to work better then stack

This is what I see in chrome: Chrome

This is the code:

function openWindow(winUrl,winName,winParams)
	{
		var win = window.open(winUrl, winName, winParams);
		win.focus();
	}
  
function showInspection(inspectionId){
     alert('inspectionId:' + inspectionId);
     openWindow('http://www.africau.edu/images/default/sample.pdf','fullscreen=no,resizable=yes,scrollbars=auto,menubar=yes,location=0,status=1');
			}
<a download target="_blank" href="javascript:showInspection('1')">
<img title="download1" src="https://cdn0.iconfinder.com/data/icons/bremen/32/phone.png"/>
</a>
<a download target="_blank" href="javascript:showInspection('2')">
<img title="download2" src="https://cdn0.iconfinder.com/data/icons/bremen/32/phone.png"/>
</a>
<a download target="_blank" href="javascript:showInspection('3')">
<img title="download3" src="https://cdn0.iconfinder.com/data/icons/bremen/32/phone.png"/>
</a>

I am not sure why but this code is working fine on eclipse, but not on stackoverflow editor - although chrome show the same symptoms.

UPDATE

I added a codepan that shows the issue

here is a live example

I updated chrome to Version 76.0.3809.87 (Official Build) (32-bit) now it will not show the network error just open a blank window with "about:blank" in the URL

just open a blank window with "about:blank" in the URL

Upvotes: 5

Views: 711

Answers (1)

Peter
Peter

Reputation: 2927

Updated codepen example, opens in 'debug' mode to demonstrate the code running in a more realistic envirnment than normal codepen editor. If you want to edit or see the code, this link opens the editor.

Snippet added below with modifications for quick reference (note this will not work in StackSnippets):

function openWindow(winUrl, winName, winParams) {
  var win = window.open(winUrl, winName, winParams);
  // win.focus();
}

function showInspection(inspectionId) {
  alert("inspectionId:" + inspectionId);
  openWindow(
    "http://www.africau.edu/images/default/sample.pdf",
    "fullscreen=no,resizable=yes,scrollbars=auto,menubar=yes,location=0,status=1"
  );
}

const phoneIcon = document.getElementById('phone')
phoneIcon.addEventListener('click', showInspection)
<a download target="_blank" id="phone">
  <img title="download1" src="https://cdn0.iconfinder.com/data/icons/bremen/32/phone.png" />
</a>

Upvotes: 3

Related Questions