Solved

Help needed setting a cookie based on URL parameter

Posted on 2015-01-16
3
106 Views
Last Modified: 2015-01-20
I have a email signup modal located within different sections of my site. The modals contain a button to force the modal to not be displayed again. This is done by setting a cookie.

So for example I have modals located here:
/section1/home
/section1/articles
*section1 has a url parameter of sectionID=1

/section2/home
/section2/articles
*section2 has a url parameter of sectionID=2

Is there any way to set the cookie path based on the url parameter? That way if it's set within the section, the modal won't display on /home or /articles?

This is what I'm using to set the cookie.
     $.cookie('dismiss_newsletter', 'true', { path : '/', expires : 10*365 });
0
Comment
Question by:jej07
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 40555264
Can you explain a little more about what you want to do?  Any cookie you set with path:'/' should be accessible on the next page load across your entire site.
0
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 40555337
To get the URL parameter, check out the code taken from http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html

function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++)
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)
        {
            return sParameterName[1];
        }
    }
}​

Open in new window


You could then get sectionID by calling

var sectionID = GetURLParameter('sectionID');

Open in new window


You should then be able to say

$.cookie('dismiss_newsletter', 'true', { path : sectionID, expires : 10*365 });

Open in new window

0
 
LVL 1

Author Closing Comment

by:jej07
ID: 40560938
Thank you that was a huge help.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question