473,545 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookie blocking issue with IE, javascript

1 New Member
Hi -

I'm trying to use javascript to determine if a user's browser has cookies enabled or not.

To test: copy this code into a file with a 'html' extension, and load it into your IE browser directly, through a local web server and through a remote web server.
By turning cookies on/off in your browser, running the file, then clicking the 'test1' or 'test2' buttons, the displayed text should accurately inform you if your cookies are On or Off.

FireFox behaves as expected, but IE 6 does not (surprised?).

When this script below is run from an external server, it works on IE.
But if I simply load the page 'locally' in my IE browser (drag-n-drop or File>Open), it sees that cookies are turned off. As well, if I load it via IIS on an internal network, it never sees that cookies are turned off.

It's as though it must only come from an external server to work - why?
How can I make it work in IE 6 regardless of where the page came from?

Thanks....

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <input type="button" value="test1" onclick="javascript:test1();">
  3. <input type="button" value="test2" onclick="javascript:test2();">
  4. <input type="button" value="kill all" onclick="javascript:killAll();">
  5. <div name="test" id="test"></div>
  6. <script language="JavaScript">
  7. function killAll(){
  8.     killCookie('test1');
  9.     killCookie('test2');
  10.     document.getElementById("test").innerHTML='';
  11. }
  12. function killCookie(cookieName){
  13.     if(document.cookie.indexOf(cookieName)!=-1){
  14.         document.cookie=cookieName+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
  15.     }
  16. }
  17. function test1(){
  18.     var cookieName='test1';
  19.     killCookie(cookieName);
  20.     document.getElementById("test").innerHTML='';
  21.     var today=new Date();
  22.     var expire=new Date();
  23.     expire.setTime(today.getTime()+60000);
  24.     document.cookie=cookieName+"=;expires="+expire.toGMTString();
  25.  
  26.     if (document.cookie.indexOf(cookieName)!=-1){
  27.         document.getElementById('test').innerHTML='<b>test1=Cookies are currently enabled in your browser.</b>';
  28.     }else{
  29.         document.getElementById('test').innerHTML='<b>test1=Cookies are NOT currently enabled in your browser.</b>';
  30.     }
  31. }
  32.  
  33. function test2(){
  34.     var cookieName='test2';
  35.     killCookie(cookieName);
  36.     document.getElementById('test').innerHTML='';
  37.     document.cookie=cookieName;
  38.     if (document.cookie.indexOf(cookieName)!=-1){
  39.         document.getElementById('test').innerHTML='<b>test2=Cookies are currently enabled in your browser.</b>';
  40.     }else{
  41.         document.getElementById('test').innerHTML='<b>test2=Cookies are NOT currently enabled in your browser.</b>';
  42.     }
  43. }
  44. </script>
  45. </html>
Mar 9 '07 #1
3 2579
acoder
16,027 Recognized Expert Moderator MVP
Welcome to The Scripts (TSDN)..

This may not be the problem, but IE can be picky about forms. You should define form tags. Also you have no body tags.
Mar 9 '07 #2
Exsuscito
1 New Member
I'm having the same issue (I believe) with an AJAX RPC call. For some reason only RPC server methods receive an old / stale cookie while all other standard pages work correctly and always receive the up-to-date cookie.

This doesn't happen in FireFox, but it does in IE 6, and it only occurs when I am calling http://localhost/xxx/yy. I am able to work-around it if I access http://domain.name/xxx/yy, where "domain.nam e" resolves to my PC anyway.

Strange behaviour that accessing AJAX RPC methods (i.e. using ActiveX object 'Microsoft.XMLH TTP') via http://localhost/xxx/yy would cause IE to send a stale cookie.

However this is a hassle, and not an ideal solution for longterm application development on a small LAN.
Apr 10 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Check out this link and see if it solves your problem.
Apr 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

18
8815
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page (same folder). The cookie is not received. Can someone explain why? I worked around this by adding a cache-control header with a value of...
6
2095
by: Mark | last post by:
I am designing a game for a forum. When the user has finished playing I need to save their data to a cookie then navigate to a page which holds their score data (I can't have both sets of data on the same page because I can't control the forum design). The score data is updated with the results held in the cookie and the cookie is deleted. I...
15
3633
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via HttpCookie.Expires property, but property value is the time of day on the client. How can I possibly know client local time ?
3
11104
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the...
3
3366
by: mike.biang | last post by:
I am using the XMLHTTP object to request a page from within another ASP page. For my scenario, the two pages should operate in the same session. However, when I request the second page, a new session is created. This makes sense since it is coming from a different client (the XMLHTTP object as opposed to my browser). I've tried to pass...
1
1590
by: flutetones | last post by:
http://67.189.52.24/~metafusionserver/public_html/training.php Here is a link to my server. I have an issue that doen't make sense. What's hapening is this . . . What's going right . . .
2
1692
by: RootShell | last post by:
I have been experiencing a lot of troubles in reading a PHP COOKIE from javascript. if i write the cookie and read it in javascript in the same PHP file it works well, but if i write the cookie for instance in a Javascript(AJAX) called PHP file, the Javascript can read it. Any ideas why? This is a Javascript issue and not PHP, that's...
5
3155
by: cbhoem | last post by:
Hi - I am trying my hand at python cookies. I'm confused about a few things though. Do the python cookies get written to a cookies text file? I have simple code below -- I see the cookie in my HTTP header but do not get anything in the cookie text file. I'm working on linux. print "Content-type: text/html" cookie =...
16
2959
by: Stevo | last post by:
I'm guessing this is a laughably obvious answer to many here, but it's not to me (and I don't have a server or any knowledge of PHP to be able to try it). It's not strictly a PHP question, but something that PHP guys would know the answer to. I can't think of a more appropriate forum to try. I've heard the ASP and JSP guys aren't as friendly...
0
7453
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7742
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5318
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4940
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1007
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.