473,466 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Create 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 2563
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.name" resolves to my PC anyway.

Strange behaviour that accessing AJAX RPC methods (i.e. using ActiveX object 'Microsoft.XMLHTTP') 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
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...
6
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...
15
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...
3
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...
3
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...
1
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
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...
5
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...
16
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.