Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help needed setting a cookie based on URL parameter

Posted on 2015-01-16
3
Medium Priority
?
109 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 51

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

604 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