Zen Cart Logo
Forums / Code Collaboration / Main page javascript

Main page javascript

Views: 8,096

Results 1 to 7 of 7
06 May 2018, 00:35
#1
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Main page javascript

I'm trying to install some javascript in the html that creates the main page. The script must be placed in the html head (before the </head> for the main page, but I'm struggling to find out where that html exists. In addition, I need to condition adding the javascript based on a variable I've created. I'm trying to integrate a cookie disclosure script that will display a cookie use disclosure the first time a user goes to the home page for EU GDPR.

If I put the javascript in the includes/modules/pages/index folder, I assume the javascript will be made available for the main page, but where can I add the test that conditionally adds the script to the html?

Thanks in advance for steering me to the correct file.

06 May 2018, 05:38
#2
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Main page javascript

The JavaScript should be renamed, to jscript_YOURSCRIPT. And should be placed in includes/templates/YOUR_TEMPLATE/ jscript. This way it loads on every page, and not only on the main page. Most visitors will never see your main page but go straight to the product page.

06 May 2018, 20:04
#3
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Main page javascript

Good idea Design75. Thanks! Implemented my php conditional (if-else structure) in my javascript file, named it jscript_[myscriptname].php and put it in the location you suggested. Works great. I'm constantly amazed at the flexibility of the Zen Cart framework. Great work developers!

06 May 2018, 20:52
#4
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Main page javascript

Thank for reporting back.
BTW which script are you using?

07 May 2018, 12:12
#5
dave224 avatar

dave224

Zen Follower

Join Date:
Jun 2012
Posts:
481
Plugin Contributions:
0

Re: Main page javascript

I'm using a script from Cookie Consent by Insights. I wrote some observer code to get the users country from their IP address through ipinfo.io, and am using the cookie script to display the informational "cookies used here" message for users in the EU countries. i could probably use the geolocation services in Cookies Consent instead of my observer code, but the javascript to do so is a bit above my capabilities.

10 May 2018, 18:12
#6
fjolsvith avatar

fjolsvith

New Zenner

Join Date:
Mar 2016
Location:
Norcatur, Kansas, USA
Posts:
88
Plugin Contributions:
2

Re: Main page javascript

Dave224:

I'm using a script from Cookie Consent by Insights. I wrote some observer code to get the users country from their IP address through ipinfo.io, and am using the cookie script to display the informational "cookies used here" message for users in the EU countries. i could probably use the geolocation services in Cookies Consent instead of my observer code, but the javascript to do so is a bit above my capabilities.

How does this work for users who are using a VPN to mask their actual location?

10 May 2018, 18:36
#7
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Main page javascript

Fjolsvith:

How does this work for users who are using a VPN to mask their actual location?

That depends on what IP they use. But that is not your problem,if someone chooses to hide his real location.