472,978 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 software developers and data experts.

Trying to set a cookie onto self.parent.window.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 9511
> self.parent.window.opener.document.writeln(documen t.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.cookie = name + '=' + escape(value) + ';expires='+
expire.toGMTString();

To:
docCookie.cookie = name + '=' + escape(value) + ';expires='
+expire.toGMTString();
......

And then:
setCookie('val_chat', '**DELETE**', -1,
self.parent.window.opener.document);
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.window.opener.document.writeln(documen t.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.cookie = name + '=' + escape(value) + ';expires='+
expire.toGMTString();

To:
docCookie.cookie = name + '=' + escape(value) + ';expires='
+expire.toGMTString();
.....

And then:
setCookie('val_chat', '**DELETE**', -1,
self.parent.window.opener.document);
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**********************@z14g2000cwz.googlegroups .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.javascripter.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.toGMTString();
    }
    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.getDate()+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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.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
    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>...
    1
    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...
    2
    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...
    4
    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...
    4
    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...
    4
    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....
    7
    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 =...
    1
    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...
    1
    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...
    2
    by: DJRhino | last post by:
    Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
    2
    isladogs
    by: isladogs | last post by:
    The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
    0
    by: Aliciasmith | last post by:
    In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
    2
    by: giovanniandrean | last post by:
    The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
    0
    isladogs
    by: isladogs | last post by:
    The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
    3
    by: nia12 | last post by:
    Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
    0
    NeoPa
    by: NeoPa | last post by:
    Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
    0
    isladogs
    by: isladogs | last post by:
    The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
    4
    by: GKJR | last post by:
    Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

    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.