?
Solved

Script to cascade popup windows works, but with limitations.  500 Points possible.

Posted on 2003-03-14
14
Medium Priority
?
218 Views
Last Modified: 2006-11-17
The following script is designed to open a pop-up window, and cascade other windows that are opened subsequently.  It works perfectly, with the following limitation:

When you navigate away from the calling page, then return to it, it starts over, and replaces the pop-up windows.

function PopNSubmit() {
     counter = 1;

     while (top.window["Remote"+counter] && top.window["Remote"+counter].closed == false) {
     counter = counter + 1
     }

     win = 'Window' + counter;
     placement = counter*20;
     window["Remote"+counter] = window.open("index.cfm?fuseaction=Home.Building_Report",win,"width=640,height=480,top=" + placement +  ",left=" + placement +  ",menubar=yes,scrollbars=yes,resizable=yes");
     document.Form1.target = win;
     setTimeout("document.Form1.submit()", 1000);

}
</script>

I'm looking for a fix to the above code, without changing the base functionality.  If that is not possible, I'm looking for an authoritative answer as to why it's not possible.  If I get a solution, I'll reward the Expert with an additional 250 points.

0
Comment
Question by:JimV_ATL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 3

Expert Comment

by:gph
ID: 8154698
Me again :)

I don't know is this works.  I'm thinking if you've named the windows you might still be able to refer to them when you return.  I could be wrong.

if (!window["Remote"+counter]) {
//open window
}
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 8155471
Put the "counter" outside of function as global var and you need no popup existence check anymore.

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8155485
And if you have to check in subsequent windows for parent windows count, then try using session cookie counter.

Good luck,
Zvonko

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:lil_puffball
ID: 8155798
I'd stick to Zvonko's solution--use a cookie.

For example...

<script>
function PopNSubmit() {
  if(document.cookie)  
counter = 1;

    while (top.window["Remote"+counter] && top.window["Remote"+counter].closed == false) {
    counter = counter + 1
    }

    win = 'Window' + counter;
    placement = counter*20;
    window["Remote"+counter] = window.open("index.cfm?fuseaction=Home.Building_Report",win,"width=640,height=480,top=" + placement +  ",left=" + placement +  ",menubar=yes,scrollbars=yes,resizable=yes");
    document.Form1.target = win;
    setTimeout("document.Form1.submit()", 1000);

//sets expiration date
var Expiration = new Date();
var expTime = 1000*60*60*24*30;
Expiration.setTime(Expiration.getTime() + expTime);

document.cookie="CookieName = " +counter+ "; expires=" + Expiration.toGMTString();
}
</script>
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 8155799
I'd stick to Zvonko's solution--use a cookie.

For example...

<script>
function PopNSubmit() {
  if(document.cookie)  
counter = 1;

    while (top.window["Remote"+counter] && top.window["Remote"+counter].closed == false) {
    counter = counter + 1
    }

    win = 'Window' + counter;
    placement = counter*20;
    window["Remote"+counter] = window.open("index.cfm?fuseaction=Home.Building_Report",win,"width=640,height=480,top=" + placement +  ",left=" + placement +  ",menubar=yes,scrollbars=yes,resizable=yes");
    document.Form1.target = win;
    setTimeout("document.Form1.submit()", 1000);

//sets expiration date
var Expiration = new Date();
var expTime = 1000*60*60*24*30;
Expiration.setTime(Expiration.getTime() + expTime);

document.cookie="CookieName = " +counter+ "; expires=" + Expiration.toGMTString();
}
</script>
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 8155814
Whoops! I don't know how but I accidentally submitted while still typing. Guess I pressed tab and then enter or something...
Anyways, forget that and try this:

<script>
function PopNSubmit() {
 if(document.cookie) {
  counter = document.cookie.substring(document.cookie.indexOf('=')+1,document.cookie.length);
}
else{counter=1)

   while (top.window["Remote"+counter] && top.window["Remote"+counter].closed == false) {
   counter = counter + 1
   }

   win = 'Window' + counter;
   placement = counter*20;
   window["Remote"+counter] = window.open("index.cfm?fuseaction=Home.Building_Report",win,"width=640,height=480,top=" + placement +  ",left=" + placement +  ",menubar=yes,scrollbars=yes,resizable=yes");
   document.Form1.target = win;
   setTimeout("document.Form1.submit()", 1000);

//sets expiration date
var Expiration = new Date();
var expTime = 1000*60*60*24*30;
Expiration.setTime(Expiration.getTime() + expTime);

document.cookie="CookieName=" +counter+ "; expires=" + Expiration.toGMTString();
}

document.cookie="CookieName = " +counter+ "; expires=" + Expiration.toGMTString();
}
</script>
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8155844
i had thot about this idea too.. but unfortunately it is flawed..
if the user browses away from the main page.. then closes some of the popup windows..
it will not track the removed windows correctly
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8155868
to show the example.. get this implementation working then..
browse away from the main calling page
remove a couple of random windows
browse back to the main page and try making popups
you will see that the placement will reflect the state right before u navigated away from the main page..
but not any of the removals you made while navigated away
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 8155912
Hmmm. Theoretically it would work. However, I've just found out that it doesn't treat the cookie value as a number, rather a string. Therefore adding 1 will get you '11' rather than 2. This is a problem that I'll try to fix...
Also take note that in else{counter=1) should really be else{counter=1} (curly bracket, not round)
0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 8155916
Oh, then there's the problem sh0e pointed out, sorry didn't see your post before...
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8155935
np

btw if you have problems with document.cookie as a string
use parseInt(<string>,<radix>)
string being the string to convert
radix being the number base
you will most likely only deal with base 10 so..
parseInt(document.cookie,10)
is what you want
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8157720
Hey boys and girls, are you solving self produced problems???

No radix needed when incrementing a string value!
Simply do this and it will always be handled as decimal number:
 counter*1+1

That's all.

PS: this default octal problem occurs only when leading zeros are inserted in front of the number.

0
 
LVL 5

Author Comment

by:JimV_ATL
ID: 8159212
Sorry for my lack of reponse.  Email server problems.

sh0e is correct, that there is a flaw in using the global cookie counter, however, that is, indeed, a solution.  From my standpoint, I'll propose that to the business and let them decide the better solution (or the lesser disadvantage).

I'm increasing the points to 500 and awarding the question to Zvonko.  Zvonko, please make a post to http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20553785.html so you can collect those 100 points as well.

lil_puffball, thanks for your code.  I'm going to post a points for lil_puffball question.

0
 
LVL 12

Expert Comment

by:lil_puffball
ID: 8162304
sh0e and Zvonko,
Thanks for telling me a solution for that problem!

Jim,
Well, I suppose this problem is sort of tricky. You can try to fix it but nothing will ever be perfect because once you exit the window, all connection is lost to the child windows. I suppose you could try editing the cookie value with an onunload in the child windows, however this might no work, I'm not sure...
Anyways, thanks for the points and I hope everything works out for you!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question