473,698 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to set a cookie onto self.parent.win dow.opener

I thought this would work but it seems to not work neither in Netscape
nor in IE:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. // OBTAINED FROM http://www.javascripter.net/faq/settinga.htm
  5.  
  6. // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
  7. AND THUS EXPIRE
  8. function setCookie(name, value, days) {
  9. var today = new Date();
  10. var expire = new Date();
  11. if (days == null || isNaN(days) || days == 0) days = 1;
  12. if (days >= 1 || days < 0) expire.setTime(today.getTime() + 3600000 *
  13. 24 * days);
  14. document.cookie = name + '=' + escape(value) + ';expires=' +
  15. expire.toGMTString();
  16. }
  17.  
  18.  
  19. setCookie('val_chat', '**DELETE**', -1);
  20. self.parent.window.opener.document.writeln(document.cookie); //
  21. DELETE PARENT WINDOW'S COOKIE
  22. self.parent.window.opener.location.href = 'chat.jsp';
  23. self.parent.close();
  24. //-->
  25. </script>
  26. <noscript><!-- NO EQUIVALENT --></noscript>
  27.  
However, instead of the expired cookie being set into the frame's
parent's window.opener document, nothing is set, however, redirection
takes place but incorrectly since the cookie's instance still exists
when the window.opener is refreshed.

So how have you guys done this correctly where I have gone wrong?

Thanx
Phil

Feb 6 '06 #1
4 9716
> self.parent.win dow.opener.docu ment.writeln(do cument.cookie); //
DELETE PARENT WINDOW'S COOKIE


This code write something to parent window document, but not operate
with its cookie.
Try to add extra parameter to the function "setCookie" :
function setCookie(name, value, days, docCookie)
{
.....

Change:
document.cook ie = name + '=' + escape(value) + ';expires='+
expire.toGMTS tring();

To:
docCookie.cooki e = name + '=' + escape(value) + ';expires='
+expire.toGMTSt ring();
......

And then:
setCookie('val_ chat', '**DELETE**', -1,
self.parent.win dow.opener.docu ment);
Maybe it works, but I don't test.

Feb 6 '06 #2
I'm sorry I do not understand this. :(

Phil

marss wrote:
self.parent.win dow.opener.docu ment.writeln(do cument.cookie); //
DELETE PARENT WINDOW'S COOKIE


This code write something to parent window document, but not operate
with its cookie.
Try to add extra parameter to the function "setCookie" :
function setCookie(name, value, days, docCookie)
{
....

Change:
document.cook ie = name + '=' + escape(value) + ';expires='+
expire.toGMTS tring();

To:
docCookie.cooki e = name + '=' + escape(value) + ';expires='
+expire.toGMTSt ring();
.....

And then:
setCookie('val_ chat', '**DELETE**', -1,
self.parent.win dow.opener.docu ment);
Maybe it works, but I don't test.


Feb 6 '06 #3

Phil Powell wrote:
I thought this would work but it seems to not work neither in Netscape
nor in IE:

Expand|Select|Wrap|Line Numbers
  1.   <script type="text/javascript">
  2.   <!--
  3.  // OBTAINED FROM http://www.javascripter.net/faq/settinga.htm
  4.  // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
  5.  AND THUS EXPIRE
  6.  function setCookie(name, value, days) {
  •  
  • Add extra parameter docCookie:
  • function setCookie(name, value, days, docCookie) {
  •  
  •   var today = new Date();
  •   var expire = new Date();
  •   if (days == null || isNaN(days) || days == 0) days = 1;
  •   if (days >= 1 || days < 0) expire.setTime(today.getTime() + 3600000 *
  •  24 * days);
  •   document.cookie = name + '=' + escape(value) + ';expires=' +
  •  expire.toGMTString();
  •  
  • Set desired value to docCookie:
  • docCookie = name + '=' + escape(value) + ';expires=' +
  • expire.toGMTString();
  •  
  •  }
  •      setCookie('val_chat', '**DELETE**', -1);
  •  
  • Sorry, I was wrong here, last parameter must be
  • self.parent.window.opener.document.cookie
  • (not self.parent.window.opener.document)
  •  
  • setCookie('val_chat', '**DELETE**', -1,
  • self.parent.window.opener.document.cookie);
  •      self.parent.window.opener.document.writeln(document.cookie); //
  •  
  • Function writeln() writes content of document.cookie to
  • self.parent.window.opener.document but not set its cookie. To set
  • cookie of self.parent.window.opener.document you should do it directly:
  • self.parent.window.opener.document.cookie="...". I guess this line of
  • code is wrong.
  •  DELETE PARENT WINDOW'S COOKIE
  •      self.parent.window.opener.location.href = 'chat.jsp';
  •      self.parent.close();
  •  
  • I don't understand what are you going to achieve with this code and
  • can't comment it.
  • Sorry for my English
  •    //-->
  •   </script>
  •   <noscript><!-- NO EQUIVALENT --></noscript>
  •  

  • However, instead of the expired cookie being set into the frame's
    parent's window.opener document, nothing is set, however, redirection
    takes place but incorrectly since the cookie's instance still exists
    when the window.opener is refreshed.

    So how have you guys done this correctly where I have gone wrong?

    Thanx
    Phil

    Feb 7 '06 #4
    JRS: In article <11************ **********@z14g 2000cwz.googleg roups.com>
    , dated Mon, 6 Feb 2006 00:50:21 remote, seen in
    news:comp.lang. javascript, Phil Powell <ph************ **@gmail.com>
    posted :
    I thought this would work but it seems to not work neither in Netscape
    nor in IE:

    [code]
    <script type="text/javascript">
    <!--

    // OBTAINED FROM http://www.javascripte r.net/faq/settinga.htm
    Clearly a site to be avoided.

    // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
    AND THUS EXPIRE
    function setCookie(name, value, days) {
    var today = new Date();
    var expire = new Date();
    if (days == null || isNaN(days) || days == 0) days = 1;
    if (days >= 1 || days < 0) expire.setTime( today.getTime() + 3600000 *
    24 * days);
    document.cookie = name + '=' + escape(value) + ';expires=' +
    expire.toGMTSt ring();
    }
    There's no need to create two Date Objects just to get an Object set to
    24 hours ahead of now.

    To get a Date Object whose value does not matter, use new Date(0)
    which is quicker. To get a new Date Object E with the same value as a
    Date Object D, use E = new Date(+D) .

    3600000 * 24 is better written as 864e5.

    Code posted should be executable as posted. Do not allow your posting
    agent to wrap lines.

    You can advance 24 hours, but the description is in terms of days.
    Civil days do not always have 24 hours; if you describe the expiry in
    days, your users may occasionally get surprised.

    Use var T = new Date() ; T.setDate(T.get Date()+1)

    Your code seems to assume that the value of days is integer, without
    ensuring that.
    So how have you guys done this correctly where I have gone wrong?


    Your code no doubt does exactly what it should do. You have failed to
    say what you want it to do.

    It seems that days is read from a user control. If you check the
    control with a RegExp you can assure a good value; consider and test

    S = control.value
    OK = /^[+-]?\d+$/.test(S) // repeat if false?
    days = OK ? +S : 1

    I suppose that you have checked the incipient cookie string S with, say,
    alert(S); probably the error whose consequences you refer to lies
    elsewhere.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Feb 7 '06 #5

    This thread has been closed and replies have been disabled. Please start a new discussion.

    Similar topics

    1
    11104
    by: Debbie Davis | last post by:
    Hi there, I'm not very good at javascript but I'm using the following to close a child window and refresh a parent window after updating a database. It's within an ASP page. CODE <SCRIPT> function CloseWindow() { if (window.opener && !window.opener.closed) { window.opener.document.location.reload(); window.close();
    1
    3741
    by: Marshall Dudley | last post by:
    I have an application where in a shopping cart checkout a popup appears which suggests other items that may go with what was ordered with a button to add these items to the cart. When the button in the popup is clicked, the popup should present an added items to cart message, close, and reload the parent window, so the parent will show the new item in the cart. It is all working except the post contents for the parent window are being...
    2
    5097
    by: Snolly | last post by:
    Hi all, Here is my issue. I have a web page (lets call it page1) with an iframe in it that then opens a pop-up window (page2). The pop-up window is used to edit some data that was loaded into page1 so I want to use onunload to reload page1 to keep the data synchronized. At first I was using just window.opener.parent.location = window.opener.parent.location;
    4
    10489
    by: Davey | last post by:
    I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a description and a class_id (stored in the value attribute of each option). The user will then select a class from the drop-down list. What I want to do is have a control in the parent browser window which can store the class_id and the...
    4
    2763
    by: Earl Teigrob | last post by:
    I am thinking about using a popup window to edit settings that will affect parent asp.net page. The data that is changed in the popup window will be saved to the datastore that is loaded and displayed by the parent page. In order to refresh the parent page, I would like to raise an event in the popup (child) page that is subscribed to by the parent so that I can rebind the data in the parent page once the data in the child window data is...
    4
    14466
    by: stevong | last post by:
    It works on Konquerer though. I remember it works on IE too. I've tried window.close() too. Doesn't work on Firefox also. I've also tried to create a function. It doesnt work on Firefox also. Bottomline is: Firefox doesn't accept window.close() or self.close()? Are there ways to rectify the issue? Please advise.
    7
    6079
    by: Alan Little | last post by:
    I have a popup which contains a frame set; one of the frames contains a form. When the form is submitted, I want it to go back to the opener of the popup. I have: document.forms.target = parent.opener; But on submit it opens a new window. If I put: document.write(parent.opener.name);
    1
    4340
    by: zxo102 | last post by:
    Hi everyone, I have tried two days to figure out how to draw the image in wx.BufferedDC on the page created by AddPage of wx.Notebook but still got no clue. The attached example works fine. If I click the menu "Draw" --"New Drawing". The image with wx.BufferedDC/wx.BufferedPaintDC can move around on the frame. But If I uncomment those three commented lines in "class TestFrame" to add a new page (from wx.Notebook) with a tag and modify...
    1
    4505
    by: michal.podlewski | last post by:
    Hi All, I have a problem with a simple (as I thought till now) thing: I want to make a link in a child-window which would change site in the parent-window and along with closing child window. The parent window name is "main". A made a link like this in the child-site: <a href="new_address.html" target="main" class="about" onclick="javascript:main.location='new_address.html';self.close();"> change and close </a>
    0
    9170
    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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
    0
    9031
    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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
    0
    8876
    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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
    0
    7741
    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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
    0
    5867
    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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
    0
    4372
    by: TSSRALBI | last post by:
    Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
    0
    4624
    by: adsilva | last post by:
    A Windows Forms form does not have the event Unload, like VB6. What one acts like?
    1
    3052
    by: 6302768590 | last post by:
    Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
    3
    2007
    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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

    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.