/    Sign up×
Community /Pin to ProfileBookmark

javascript and frames problems, function call repeatedly, why?

Below is the code that I have been working with. I’ve set up a frame and I want to catch when a user closes or navigates away from the frame main page. The functions below do just that but despite the “parent” the exitCheck() and assuming the test() function are called for the the pages accessed through the frame, so although it does work the message is repeated several times and it is annoying. I only want to display the message if the main/parent page is closed. Any thoughts to what I am doing wrong?

I assume this is because all the windows in the frame are closing, but I just can’t seem to stop the message from being displayed not matter what I do.

~Phoenix

[CODE]<HTML>
<HEAD>
<META HTTP-EQUIV=”PRAGMA” CONTENT=”NO-CACHE”>
<TITLE>Main</TITLE>
<script type=”text/javascript”>
parent.onbeforeunload = exitCheck;
parent.onunload = test;

function test(){

parent.location = “systemlogout.php”;

}
function exitCheck(evt){
return “You are currently accessing a secure system and the navigation has been locked to prevent data loss.”
}
</script>
</HEAD>
<FRAMESET border=0 rows=”100%,*” frameborder=”no” marginleft=0 margintop=0 marginright=0 marginbottom=0>
<frame src=”123.php” NAME=”main” scrolling=auto frameborder=”no” border=0 noresize>
</FRAMESET> <NOFRAMES>You must use a browser that can display frames
to see this page. </NOFRAMES>
</HTML>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliJul 10.2007 — Below is the code that I have been working with. I've set up a frame and I want to catch when a user closes or navigates away from the frame main page. The functions below do just that but despite the "parent" the exitCheck() and assuming the test() function are called for the the pages accessed through the frame, so although it does work the message is repeated several times and it is annoying. I only want to display the message if the main/parent page is closed. [/QUOTE]
The first thing I would try would be to have the handlers cancel themselves:
[CODE]<script type="text/javascript">
parent.onbeforeunload = exitCheck;
parent.onunload = test;

function test(){
[B]this.onunload=null;[/B]
parent.location = "systemlogout.php";
}
function exitCheck(evt){
[B]this.onbeforeunload=null;[/B]
return "You are currently accessing a secure system and the navigation has been locked to prevent data loss."
}
</script>
[/CODE]
Copy linkTweet thisAlerts:
@phoenix401authorJul 10.2007 — can't believe it was that simple, thanks a lot for the help!
×

Success!

Help @phoenix401 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...