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.

·2 min read·View Oracle Docs

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.

javascript
1"text-purple-400">define('NetSuite.MyCookiesExtension.Footer.View',
2 [
3 'SCView',
4 'jQuery',
5 'netsuite_mycookiesextension_footer.tpl'
6 ],
7 "text-purple-400">function (SCViewComponent, jQuery, netsuite_mycookiesextension_footer_tpl) {
8 'use strict';
9
10 "text-purple-400">var SCView = SCViewComponent.SCView;
11
12 "text-purple-400">function MyCookiesExtensionFooterView() {
13 SCView.call("text-purple-400">this);
14
15 "text-purple-400">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 = "text-purple-400">function() {
23 "text-purple-400">return;
24 }
25
26 MyCookiesExtensionFooterView.prototype.getEvents = "text-purple-400">function() {
27 "text-purple-400">return {
28 'click #myCookiesExtensionCookiesLink': 'showCookiesBanner'
29 }
30 }
31
32 MyCookiesExtensionFooterView.prototype.showCookiesBanner = "text-purple-400">function() {
33 jQuery('#myCookiesExtensionBanner').show();
34 window.scrollTo(0,0);
35 }
36
37 "text-purple-400">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 getEvents method binds the click event to the showCookiesBanner function.
  • Banner Display: The function showCookiesBanner controls 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:

html
<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.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

How do I bind a click event to a function for showing a cookies banner in SuiteCommerce?
In the footer view JavaScript code, you use the `getEvents` method to bind a click event to the `showCookiesBanner` function, which is defined to show the cookies banner and scroll the window to the top.
Do I need to create a template for the footer view in SuiteCommerce?
Yes, a template is necessary to define the visual structure of the footer. This is initialized in the view with the `template` property pointing to your HTML template file.
What is the purpose of the `showCookiesBanner` function in the JavaScript code for SuiteCommerce?
The `showCookiesBanner` function controls the display of the cookies banner by using jQuery to show the element when the link is clicked. It also ensures the window scrolls to the top to make the banner visible to users.
What HTML elements are required to incorporate a cookies policy link in the SuiteCommerce footer view?
You need an HTML structure that includes a `<div>` element containing an `<a>` tag with an ID for the cookies policy link, which triggers the banner display when clicked.
Source: Create a View for the Footer Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →