[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Cookie problem in Safari browser

Posted on 2007-12-03
4
Medium Priority
?
2,702 Views
Last Modified: 2012-05-05
I have a page index.html and have a link on it "Link 1".  The HTML code for this link is <a href="page2.html?seg=setSegXYZ">
On this page2.html, there is a call to the function getStart('PageToOpen.html','CookieName')

Thus, basically on clicking the link "Link 1" on the index page, PageToOpen.html is called by setting the cookie "CookieName"

The cookie is set via a query string.  The exact code for setting the cookie is
document.cookie = name + "=" + escape(style) + "; expires=" + expire.toGMTString();

Here name is the Cookie name.

The problem is that this works fine in IE and Firefox. However, when I open the sam page in Safari, it seems that the cookie does not set and the page kind of loops back and forth (i.e. page X calls page Y, which again calls page X and so on).

As an additional info, I have set my browser to accept all cookies and another interesting thing is that this problem occurs locally, while the same js works fine on the live site(www)

I am not sure where the problem is. Please suggest.

document.cookie = name + "=" + escape(style) + "; expires=" + expire.toGMTString();

Open in new window

0
Comment
Question by:askanyquestions123
[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
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 20396017
Use theattached code

Put it in an external file called cookie.js
// cookie.js file
var cookieToday = new Date(); 
var expiryDate = new Date(cookieToday.getTime() + (365 * 86400000)); // a year
 
/* Cookie functions originally by Bill Dortsch */
 
function setCookie (name,value,expires,path,theDomain,secure) { 
   value = escape(value);
   var theCookie = name + "=" + value + 
   ((expires)    ? "; expires=" + expires.toGMTString() : "") + 
   ((path)       ? "; path="    + path   : "") + 
   ((theDomain)  ? "; domain="  + theDomain : "") + 
   ((secure)     ? "; secure"            : ""); 
   document.cookie = theCookie;
} 
 
function getCookie(Name) { 
   var search = Name + "=" 
   if (document.cookie.length > 0) { // if there are any cookies 
      var offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value 
         var end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value 
         if (end == -1) end = document.cookie.length 
         return unescape(document.cookie.substring(offset, end)) 
      } 
   } 
} 
function delCookie(name,path,domain) {
   if (getCookie(name)) document.cookie = name + "=" +
      ((path)   ? ";path="   + path   : "") +
      ((domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20396086
Use:

setCookie("Cookiename","CookieValue",expiryDate)

and

var val = getCookie("Cookiename")
0
 

Author Comment

by:askanyquestions123
ID: 20397414
ok..Thanks I will use this code and get back to you, if I have any queries.
0
 

Author Closing Comment

by:askanyquestions123
ID: 31412291
Thanks a lot..Very helpful answer.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses

656 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