cross page persistence

V

VisionSet

I need to persist some objects across page navigations, I am under the
impression that on each new page a new set of top level objects are
provided so I don't know where, how or if I can persist my own objects.
Any advice please?

TIA,
Mike W
 
V

VisionSet

VisionSet said:
I need to persist some objects across page navigations, I am under the
impression that on each new page a new set of top level objects are
provided so I don't know where, how or if I can persist my own objects.
Any advice please?


The object I wish to persist are window objects. I create them in one
page but the user may navigate away from this page and hence I need a
central repository to store the references for access from any page a
user may browse to.

TIA
Mike W
 
V

Vincent van Beveren

VisionSet said:
The object I wish to persist are window objects. I create them in one
page but the user may navigate away from this page and hence I need a
central repository to store the references for access from any page a
user may browse to.

Hi Mike,

There is no such place (as far as I know). There are some window-tricks
that you might be able to use. See the script below:

<html>

<script type="text/javascript">


function openIfNotExist(url, name) {
win = window.open("", name, "width=300,height=200");
if ('' + win.location == "about:blank") {
win = window.open(url, name);
}
win.focus();
return win;
}

function getReferenceIfExist(name) {
// rather ugly, because it opens a window
win = window.open("", name, "width=1,height=1");
if ('' + win.location == "about:blank") {
win.close();
return null;
}
return win;
}

</script>

<body>
<input type="button" value="reference" onclick="alert('ref: ' +
getReferenceIfExist('test'));">
<input type="button" value="open or focus"
onclick="openIfNotExist('test.html', 'test');">
</body>

</html>

Both functions work cross page.

OpenIfNotExist opens a window with that URL if it doesnt exist, else it
focusses that window and returns the reference.

getReferencEIfExists returns the reference of a window. However, it must
open a window before knowing whether it already exists, so a window fill
flash before your eyes if not.

Good luck,
Vincent
 
R

Richard Cornford

Vincent van Beveren wrote:
There is no such place (as far as I know). There are some window-tricks
that you might be able to use. See the script below:
function openIfNotExist(url, name) {
win = window.open("", name, "width=300,height=200");

Even if the window with the corresponding name is open this will result
in it being loaded with the URL specified in the window open call
(subject to the availability of a window.open method on the UA in
question and pop-up blockers not being in operation on the client
computer). Generally a URL specified as an empty string will be taken
as 'about:blank', though not always, with alternative such as
'opera:balnk' having been previously observed in the wild.

(incidentally, code posted to Usenet should be indented with sequences
of space characters (two to four, are suggested) as any newsreader's
representation of a tab character is an unknown quantity, ranging from
zero space (no-indentation) to values equivalent to 8 spaces or
greater, making lines wrap and rendering code hard to read.)
if ('' + win.location == "about:blank") {

Having opened the window with an empty string as the first argument
this is almost certain to be true (while occasionally being false in
circumstances which are equivalent to 'about:blank').

It also seems more reasonable to be reading the - location - object's -
href -property, which is a string, than to be type-converting the -
location - object into a string by concatenating it to an empty string.

win = window.open(url, name);
<snip>

It would be more reliable, and no worse, to just pass the URL argument
into the initial call to - window.open -, as even if the URL argument
is the current URL of a page being displayed in that window the
transition through 'about:blank' will necessitate the re-loading of
that page.

Richard.
 
V

Vincent van Beveren

It would be more reliable, and no worse, to just pass the URL argument
into the initial call to - window.open -, as even if the URL argument
is the current URL of a page being displayed in that window the
transition through 'about:blank' will necessitate the re-loading of
that page.

Richard.

Have you actually tried running the code?

Vincent
 
R

Richard Cornford

Vincent said:
Have you actually tried running the code?

Only to the extent of verifying that no content would ever get loaded
into a pop-up on current Opera browsers.

Richard.
 
V

Vincent van Beveren

Only to the extent of verifying that no content would ever get loaded
into a pop-up on current Opera browsers.

For IE and FireFox it works fine. I tried it now in and, as you said, it
doen't work (though it might with some tweaking). I understand the
theoretical problems with this code. Its rather 'hacked'. So, future
support will probably not garanteed. I was actually suprised myself that
it worked in IE and FF.

Vincent
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top