How to preserver a window's property after refresh of the page ????

T

Tom Szabo

Hi,

In order to preserve some settings and avoid cookies I have thought of the
following trick:

I simply create an array as the property of the window:

window.aList = new Array();

and add the values to be preserved for after refresh.

While I can add the values fine, once I refresh the page the array is reset,
or at least it appears to be!

Any idea how cen I preserve the property of the the window????

TIA,

Tom
 
T

Tom Szabo

"> preserve the info in cookies is one option. if you're writing asp or jsp
pages, you could preserve the info in a session object. you could also post
the info back to the page using hidden form fields.

Thanks Nancy,

But what I was trying to find out if it is possible to store some properties
to the window and retrieve them after refresh. I thought that the document
gets reloded, so it's properties will be lost, but I thought the window
would be the same, so the properties will stay...but it appears I was
wrong...

I hope I am making sense, it is getting a little late here...:))

Regards,

Tom
 
N

Nancy Drew

preserve the info in cookies is one option. if you're writing asp or jsp
pages, you could preserve the info in a session object. you could also post
the info back to the page using hidden form fields.
 
M

Michael Winter

[snip]
i believe you can reload a frame src without reloading the entire frames
document

Frames are evil[1].

[snip]

Mike


[1] Google for the reasons.
 
T

Tom Szabo

guess i misread your question. i believe you can reload a frame src
without
reloading the entire frames document, so you could do a hidden frame, stick
your data in there, reload your main frame and grab the document back from
the hidden frame. i think i've read about this as a primitive means of
writing a shopping cart application, though i've never written this myself.

hope that helps

Hi Nancy,

Thanks for your answer, I was hoping to have a little better news but this
will do too, I hope, just complicates the process a little.

Regards,

Tom
 
R

RobB

Tom Szabo said:
Hi,

In order to preserve some settings and avoid cookies I have thought of the
following trick:

I simply create an array as the property of the window:

window.aList = new Array();

and add the values to be preserved for after refresh.

While I can add the values fine, once I refresh the page the array is reset,
or at least it appears to be!

Any idea how cen I preserve the property of the the window????

TIA,

Tom

Tom: thanks for a good laugh.
In order to preserve some settings and avoid cookies I have thought of the
following trick:
[snip]

While I can add the values fine, once I refresh the page the array is reset,
or at least it appears to be!

Something in re carts, horses, etc. springs to mind.

Although the window object represents the browser window
(application), it also serves as the global object - actually pointing
to the real one - for all scripting running in a given document. To
avoid chaos and security nightmares the sandbox is cleared when a new
document is loaded - and, naturally, window properties go with it. The
exceptions are few; the only one reliable enough for what you want is
the window.name property. This is used for HTML targeting, so it must
persist across documents or be useless. It can hold strings of (iirc)
256 characters, limited to alpha/underscore...believe IE is more
flexible there. It is a nice space for storing small bits of data,
carefully. I've serialized string arrays using Array.join() for
storage, as an example.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www/w3/org/TR/xhtml1">
<head>
<title>untitled</title>
<script type="text/javascript">
//<![CDATA[

if (self.name.search('_DATA_') == -1)
self.name = '_DATA_This|is|some|more|string|data...';
else self.name = self.name.replace(/more/, 'more|more');

// ]]>
</script>
</head>
<body>
<pre>
<script type="text/javascript">
//<![CDATA[

if (self.name.search('_DATA_') != -1)
{
data = self.name.replace(/_DATA_/, '').replace(/\|/g, '\n');
document.write(data);
}

setTimeout('top.location.reload()', 3000);

// ]]>
</script>
</pre>
</body>
</html>
 
T

Tom Szabo

Although the window object represents the browser window

It seems like it is representing each FRAME not the browser!

(application), it also serves as the global object - actually pointing

It is only global within the frame itself
to the real one - for all scripting running in a given document. To
avoid chaos and security nightmares the sandbox is cleared when a new

FYI, it is not cleared, only cleared for the current frame!!!

Just done some homework/experiment!

Regards,

Tom
 
M

Michael Winter

It seems like it is representing each FRAME not the browser!

That's because frame objects (in DOM 0) are represented using window
objects. So, you'll have one window object for the frameset and other
objects for each individual frame.

[snip]

Mike
 
T

Tom Szabo

State information should be kept:
1) On the server,
2) In the URL, or
3) In cookies.

Who said it should be....??? WWW3? Even then....

Besides horses for courses MS said you should keep your config stuff in
Registry.

This resulted in the biggest stuff-ups in windows programming, most of the
install/unistall and registry corruption plus many more...

I never followed it, have never had a problem, can run multiple copies and
multiple versions of my software on the same machine at the same time...and
some vendors are starting to move back to the ini like concept...

So why am I looking for an alternative?

1) The type of info I am trying to store is difficult to store and retrieve
on/from the server....needed for JS

2) Can't be in the URL

3) Just more difficult in cookies as I would have to identify each instance
of the form in case there are mutliple instances
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top