Create Footer View with Cookies Banner in SuiteCommerce
Learn to create a footer view that displays a cookies policy link and shows a cookies banner in SuiteCommerce.
The footer view adds functionality to display a cookies policy link on your SuiteCommerce site. When users click this link, a cookies banner appears at the top of the page, and the view scrolls to the window's top. This guide will show you how to implement this using SuiteScript and jQuery.
Implementing the Footer View
To create the footer view, you need to define a new view in your SuiteCommerce application. This view will handle the click event of the link that brings up the cookies banner.
JavaScript Code Overview
Below is the JavaScript code defining the footer view, utilizing SCView, and linking the click event to an event handler.
1define('NetSuite.MyCookiesExtension.Footer.View', 2 [3 'SCView',4 'jQuery',5 'netsuite_mycookiesextension_footer.tpl'6 ], 7 function (SCViewComponent, jQuery, netsuite_mycookiesextension_footer_tpl) {8 'use strict';9 10 var SCView = SCViewComponent.SCView;11 12 function MyCookiesExtensionFooterView() {13 SCView.call(this);14 15 this.template = netsuite_mycookiesextension_footer_tpl; 16 }17 18 MyCookiesExtensionFooterView.prototype = Object.create(SCView.prototype);19 20 MyCookiesExtensionFooterView.prototype.constructor = MyCookiesExtensionFooterView;21 22 MyCookiesExtensionFooterView.prototype.getContext = function() {23 return;24 }25 26 MyCookiesExtensionFooterView.prototype.getEvents = function() {27 return {28 'click #myCookiesExtensionCookiesLink': 'showCookiesBanner' 29 }30 }31 32 MyCookiesExtensionFooterView.prototype.showCookiesBanner = function() {33 jQuery('#myCookiesExtensionBanner').show();34 window.scrollTo(0,0);35 }36 37 return MyCookiesExtensionFooterView;38 }39);In this code, several key points are essential:
- Template Initialization: The view begins by setting a template that defines the visual structure of the footer.
- Event Binding: The
getEventsmethod binds the click event to theshowCookiesBannerfunction. - Banner Display: The function
showCookiesBannercontrols the visibility of the cookies banner and scrolls the window to the top.
HTML Template for Footer View
An HTML template defines how the footer and link appear on the webpage. Below is the HTML structure required for the footer:
<div id="myCookiesExtensionFooter" class="" style="display: block; margin-left: 20px; padding: 10px;"> <a href="#" id="myCookiesExtensionCookiesLink">Cookies Policy </a></div>This code snippet creates a simple footer with a clickable link labeled 'Cookies Policy'. When clicked, it will activate the previously defined JavaScript function to show the cookies banner.
Conclusion
By following these steps, you can effectively create a footer view for your SuiteCommerce website that promotes user awareness of cookies policy through a visible link and interactive banner.
Frequently Asked Questions (4)
How do I bind a click event to a function for showing a cookies banner in SuiteCommerce?
Do I need to create a template for the footer view in SuiteCommerce?
What is the purpose of the `showCookiesBanner` function in the JavaScript code for SuiteCommerce?
What HTML elements are required to incorporate a cookies policy link in the SuiteCommerce footer view?
Was this article helpful?
More in General
- Release Notes PDF Availability in NetSuite
NetSuite provides generated PDF files for each Release Note update, enhancing accessibility and user experience.
- Commitment Credits for Billing in NetSuite SuiteBilling
Commitment Credits in SuiteBilling enhance flexible usage-based billing across services. Managing usage-based billing in NetSuite SuiteBilling has been
- Prepay Across Subscriptions in NetSuite SuiteBilling
Prepay Across Subscriptions enables efficient management of prepaid services in NetSuite SuiteBilling.
- Edit the Extension Manifest: Manual Edits
Documentation article about Manual Edits Your extension's Workspace directory includes a manifest.json file, which includes all the information required to
Advertising
Reach General Professionals
Put your product in front of NetSuite experts who work with General every day.
Sponsor This Category