Solved

FRAMESET onUnLoad and IE

Posted on 2000-04-20
12
456 Views
Last Modified: 2012-05-04
I am developing an extranet where clients log in.  In order to figure out when they leave (and do some mop up work) I set the whole extranet (after the login screen) into a 1 frame frameset.  On that page I use the frameset's onUnLoad event to do the logout mop up work, and display a goodbye window for 5 secs.  Now this works good for the most part.  If someone types an address, it will try to unload the frameset and I'm in business.
     But here's the problem.  A user, if they choose, should be able to open up a new browser window and go elsewhere.  In NS theres no problem.  The new window opens up with their homepage, and they can go anywhere they want.  But in IE the new window opens up with the eact same page as what was in the first window.  If the user then goes elsewhere on the 2nd window it triggers the onunLoad event, and the user is logged out of both windows!

     How can I work this so it doesn't happen?  Thanks in advance.

:) dapperry
0
Comment
Question by:dapperry
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 2

Expert Comment

by:dog42
ID: 2736085
Just an idea,
you could load your page into a new window when the user logs on, and then the 'mop up' function could check the window name before doing it's job.

Dog42
0
 
LVL 2

Expert Comment

by:dog42
ID: 2736111
That is,
When a user logs on, load the page to a new window:
window.open('loggedOn.htm','winName')
and then, in the frameset write:
onUnLoad="if(window.name=='winName')doLogOutF()"

You could even write a piece of code to only do this check if the browser is IE.

Dog42
0
 
LVL 2

Expert Comment

by:dog42
ID: 2736215
Sorry, ignore that.  I just realised that this would stop the cleaning function if someone typed in a url.
0
 
LVL 3

Author Comment

by:dapperry
ID: 2736304
Is there any way to tell if its the uppermost parent window?

:) dapperry
0
 
LVL 7

Expert Comment

by:nettrom
ID: 2736473
No, there's not, unfortunately (not as long as we're talking JavaScript).  JavaScript has no knowledge of other browser windows unless you've opened them (using window.open()) or you are an opened window (the 'opener' object points to your parent).
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2737522
Time to use use temporary cookie!
1. when load, check cookie not set yet
and assign handler, and set temporay cookie.
2. if cooike already set than do not assign onload handler...

Do you need cookie functions?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Accepted Solution

by:
kollegov earned 150 total points
ID: 2737523
Time to use use temporary cookie!
1. when load, check cookie not set yet
and assign handler,
2. if cooike already set than do not assign onload handler...

Do you need cookie functions?
0
 
LVL 3

Author Comment

by:dapperry
ID: 2737537
nettrom,
      If someone goes File|New|Window could the page check to see if opener is valid?  Say
 
if (self.opener) {
    //dont do anything
}
else {
    //Do the mop up stuff
}

kollegov,
    I think I get your idea.  But I think I need some example code (w/cookies) to fully get it.

:) dapperry
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2737706
Simplest way is few lines

<script>
function doclean(){
 //your clean stuff here
 //.......
 //change cookie to 'no'
 document.cookie='a=n';
}

if(document.cookie.indexOf('a=y')==-1){//assign handler and set cookie
 document.cookie='a=y';
 window.onunload=doclean;
}
</script>

You even do not need cookie functions to store single var named a with value
'y' or 'n',  you can just chech this substring exists in cookes string
0
 
LVL 3

Author Comment

by:dapperry
ID: 2752728
Kolegov,

This isn't quite working.  Heres my present code, maybe you could figure out whats going on.

<script language="javascript">
     function LogOut() {
          xpos=600;
          ypos=200;
          urlstring="logout.cfm";
winfeatures="scrollbars=yes,screenX="+xpos+",screenY="+ypos+",height=200,width=600";
            winlogout=window.open(urlstring,"winlogout",winfeatures);
          document.cookie='a=n';
      }
      if(document.cookie.indexOf('a=y')==-1){//assign handler and set cookie
          document.cookie='a=y';
        window.onunload=doclean;
    }
</script>       
<frameset rows="100%,0" border="0" onUnload="return LogOut()">
      <frame src="main.cfm">
</frameset>  


The onunLoad of the frameset is supposed to fire up a small window with a page that handles the cleanup.  I just don't want it to happen if the person wants to redirect a new browser window.

Many thanks,

:) dapperry
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2759200
This must work:

<script language="javascript">
                    function LogOut() {
                         xpos=600;
                         ypos=200;
                         urlstring="logout.cfm";
               winfeatures="scrollbars=yes,screenX="+xpos+",screenY="+ypos+",height=200,width=600";
               winlogout=window.open(urlstring,"winlogout",winfeatures);
                         document.cookie='a=n';
               }
               if(document.cookie.indexOf('a=y')==-1){//assign handler and set cookie
                    document.cookie='a=y';
                       window.onunload=LogOut;
                   }
               </script>
               <frameset rows="100%,0" border="0">
               <frame src="main.cfm">
               </frameset>  
0
 
LVL 3

Author Comment

by:dapperry
ID: 2759311
Thank you!!  That worked wonderfully.

:) dapperry
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now