Javascript Uncaught TypeError
Chrome browser displays shopping cart help information using entire screen despite javascript window.open height and width parameters in includes/modules/pages/shopping_cart/jscript_main.php code. This behavior is not encountered in Firefox and Safari browsers. The problem appears in unmodified out-of-the-box zc157c and 157d. Chrome's JavaScript Console reports an Uncaught TypeError: cannot read properties of null (reading 'focus'). Relevant code follows:
Code:
<script src="includes/general.js" type="text/javascript"></script>
<script type="text/javascript">
function popupWindow(url) {
window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=550,height=550,screenX=150,screenY=100,top=100,left=150,noreferrer')
}
function session_win() {
window.open("<?php echo zen_href_link(FILENAME_INFO_SHOPPING_CART); ?>","info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrollbars=yes,noreferrer").focus();
}
</script>
The line in red highlights where the problem lies. Removing "noreferrer" from the line eliminates the javascript error and Chrome, Firefox, and Safari all display the help text in a sized pop-up window. Also, according to W3 Schools here there is no "noreferrer" parameter, and no "statusbar" parameter, only "status".
I am only a novice with javascript. The code is from 2006. There are other cases throughout zencart where noreferrer is used in window.open. Maybe the javascript code should be reviewed and updated.
Dave
zc157c, php 8.0.2, mysql 8.0.28
Re: Javascript Uncaught TypeError
I just installed a fresh 157c and I don't get the same behavior, as far as width is concerned. The "popup" does open the full height of the window but the width is restrained. noreferrer was added by Dr. Byte in 1.5.7a, strange that it was not brought over to the 1.5.8 code in progress. Also noreferrer is allowed, see: https://developer.mozilla.org/en-US/...PI/Window/open
Re: Javascript Uncaught TypeError
Confirmed that noreferrer was added in 1.5.7a so the code was looked at recently. Installed a fresh version of Chrome (v103); the original version was v102. same problem, same javascript error. The popup window comes up sized the same size as the shopping cart page. I had Chrome sized the entire screen width and height in my original tests. Gotta be a Chrome problem, not a zen cart bug.
Re: Javascript Uncaught TypeError
The noreferrer was added for accessibility requirements BUT, this one is not required as the link is internal. If it were "referring" to the docs link, it would need to be there.
It might have been set in a batch fix of 1.5.7. It is required in the external links (e.g. ZC links in the footer).
I am getting the same view in 1.5.7 that mike is getting with Chrome 103.0.5060.53
Also, 1.5.8 draws an accuratge 460 x 430 when help is clicked.
Have you made sure there's not some css in your template that's making the change?
Re: Javascript Uncaught TypeError
But a CSS problem would affect Firefox and Safari too. Correct?
Re: Javascript Uncaught TypeError
I think the issue with "Uncaught TypeError: cannot read properties of null (reading 'focus')" is the .focus() at the end of that line. I don't believe that is required to be there.
Re: Javascript Uncaught TypeError
Quote:
Originally Posted by
dbltoe
Also, 1.5.8 draws an accuratge 460 x 430 when help is clicked.
I noted above that the noreferrer is NOT present in the 1.5.8 version of that file I find it strange that a change to 1.5.7a was not carried forward into 1.5.8
Re: Javascript Uncaught TypeError
I do prefer the way the Bootstrap template handles these "popups" by having converted them to modals.
Re: Javascript Uncaught TypeError
Sorry, didn't see the mention of the browser tests.
Normally, Chrome and Safari seem to be in lock step while Firefox does its thing. It's unusual that you are getting the same "incorrect" results from all of them.
As to the focus... Without it there, clicking a second time with the pop-up open and underneath the browser might result in the pop-up not being seen. However, it might be better coded as
Code:
newwindow=window.open("<?php echo zen_href_link(FILENAME_INFO_SHOPPING_CART); ?>","info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrollbars=yes,noreferrer");
if (window.focus) {newwindow.focus()}
I'll leave that to the experts.:P
Re: Javascript Uncaught TypeError
with focus the way it is now you can hide the popup by clicking on the page outside the popup so it doesn't do what you would want anyway. Basically, if you click the help link a second time and the popup exists it should just focus on the existing popup and not generate a new one, but the way it is currently coded I can keep clicking help and opening more popups. So it needs to be reworked in some way.