473,503 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing Cookies in Javascript.

40 New Member
I have a fully function webpage based on a Zipcode. I get the Zip code from the user once and write it the cookie and retrieve that everytime.

I also have another webpage which also asks for the zip code.

I have to synchronize these two. What i have done for this i accept the zip code also as querystrig parameter.
So from 1 website when i enter the zip code, in the javascript i have image tag and i calll the otherwebsite and load it internally.

Expand|Select|Wrap|Line Numbers
  1. if(document.images)    {    image1 = new Image();    image1.src ="http://mywebsite.com/default.aspx?zip=" + zipcode;    }
The Problem with this it writes only the cookie and doesn't load the webpage.

When i open the other wbsite i soem times see the cookie written and soem times i doesn't work.
So i'm not sure where the problem is.

Is there a better way of synchronizing the Zipcode values in both the websites.
Apr 14 '08 #1
9 1915
acoder
16,027 Recognized Expert Moderator MVP
Are the 'websites' from the same domain?
Apr 15 '08 #2
sreemathy2000
40 New Member
No they are not from the same domain. there are 2 independent websites. We are just trying to make the user enter the Zip code only once.
Apr 15 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
You could load the other website in an iframe or via Ajax (though you'd need a web proxy to avoid cross-domain issues).

The second website should have code to accept the zip parameter and write the cookie, so when you next visit the website the zipcode is set.
Apr 16 '08 #4
sreemathy2000
40 New Member
Thanks for the replies...Will try it out..
Apr 16 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
No problem, let us know if you hit any problems.
Apr 17 '08 #6
sreemathy2000
40 New Member
I implemented it using a iframe . It have a cookie in the main website which checks to see if the second website is loaded only once to avoid hit issues.

code is

Expand|Select|Wrap|Line Numbers
  1. function load() { var zipcode = getCookie('Zip'); if(zipcode) {     var IsCookie= setCookie('OnDemand');    if ((!IsCookie) || (Iscookie !=zipcode ))    {        document.write('<IFRAME SRC="http://myweebsitecom/zipcode.aspx?zip=' + twzipcode + '" WIDTH="0"HEIGHT="0"FRAMEBORDER="0"></IFRAME>');     var expdate = new Date(); expdate.setFullYear(expdate.getFullYear() + 1);    setCookie('OnDemand',zipcode,expdate);    }}}
But i'm facing a problem with this implementataion in IE.
The second website that i'm loading in the iframe has to be a trusted site to write the client side cookies which cannot be done.
How can a solution be arrived for this issue without give full trust to the website manually.
Apr 25 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
The second website that i'm loading in the iframe has to be a trusted site to write the client side cookies which cannot be done.
How can a solution be arrived for this issue without give full trust to the website manually.
What do you mean by a trusted site?

Why not have cookie writing code in the other site too? Once it's set there, it should be set when you next visit that site.
Apr 25 '08 #8
sreemathy2000
40 New Member
yes.there is a cookie written in the other site also. But only if we set the website as a trusted site, the website writes the cookie if loaded in iFrame. Otherwise, the client side cookies are not accepted by the browser.

We found a solution for this by making the other website use a P3P policy file for accepting client cookies . It works with IE7 , but it doesn't work with IE6.
Apr 25 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
That must be because of your browser settings. If you allow cookies for sites other than trusted ones, it should work.
Apr 26 '08 #10

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

Similar topics

20
3521
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
7
2985
by: Brian Burgess | last post by:
Hi all, Anyone see anything wrong with the following: *************************************************************** <%@ LANGUAGE="VBSCRIPT" %> <% Option Explicit Dim nAcctNbr Dim...
1
4358
by: Mike | last post by:
Hello, I want to read and write key'ed cookies from both javascript and ASP. I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP like the...
1
1226
by: Branner1 | last post by:
Hi there, I have a nice form working in which JS is used to "remember" the values a user enters in various fields. My problem is: - In the code, when the inital form tag is simply <FORM...
1
3165
by: John Taylor-Johnston | last post by:
I'm a University academic looking for a proper definition of JavaScript Cookies. http://www.CollegeSherbrooke.qc.ca/languesmodernes/604-HAE_Grammar_Practice/ I'm trying to decipher what...
7
2208
by: Bert | last post by:
I have been reading the post and the FAQ and have been unable to find anything that will help with my problem. First let me say that I am not a web developer, designer and no next to nothing...
0
1503
by: Amit Jamgade | last post by:
Hi, I am making use of cookies to store the Session State information through JavaScript as given below in an ASP Page. Suppose I have XYZ.asp page. The code in this page goes as shown below....
9
3048
by: SHarris | last post by:
Hello, In our new intranet ASP.NET project, two requirements are that the browser accept cookies AND JavaScript. We are requiring the use of Internet Explorer 6+. 1. Using C# in an ASP.NET...
5
10728
by: yawnmoth | last post by:
If running off of the local filesystem, in Firefox, or if the security settings are set appropriately, in Internet Exporer, XmlHttpRequests can be sent to any domain of your chosing. But what...
5
5548
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet...
0
7205
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,...
0
7093
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...
1
7008
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...
0
7467
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
5594
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
4688
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
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.