heise_man
asked on
body onFocus=functionname, not working on IE
Hi, I'm working on a flash website and am having difficulty figuring out how to have a function triggered when the window becomes active. I am having limited success with:
<body onFocus=myFadeBack();>
*myFadeBack is a function which fades the window on/off depending on whether the window is active or not.
This code works fine with Firefox and Safari, but not Internet Explorer. Is there a way to achieve this in all 3 browsers?
Here is a link of the site (test) in action.
http://www.lukeheise.com/test5/
and here are the source files:
http://www.lukeheise.com/test5/flash_files.zip
Thanks.
<body onFocus=myFadeBack();>
*myFadeBack is a function which fades the window on/off depending on whether the window is active or not.
This code works fine with Firefox and Safari, but not Internet Explorer. Is there a way to achieve this in all 3 browsers?
Here is a link of the site (test) in action.
http://www.lukeheise.com/test5/
and here are the source files:
http://www.lukeheise.com/test5/flash_files.zip
Thanks.
ASKER
Thanks Kadaba, that did work. It must be the window.onfocus that did it. However, it only seemed to worked for the alert example that you gave me.
When I apply it to my page, it fails:
http://www.lukeheise.com/test5/index9.html
* works in Firefox & Safari, but not Internet Explorer.
I'm not so much interested in the onblur code as I already have a solution for that. I'd just like for a function to be triggered when the page comes into focus.
Thanks.
When I apply it to my page, it fails:
http://www.lukeheise.com/test5/index9.html
* works in Firefox & Safari, but not Internet Explorer.
I'm not so much interested in the onblur code as I already have a solution for that. I'd just like for a function to be triggered when the page comes into focus.
Thanks.
<!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/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
object {
width: 100%;
height: 1550px;
display: block;
outline: none;
}
</style>
<script language="JavaScript">
function Launch(page, width, height) {
OpenWin = this.open(page, "kirupa", "toolbar=no, menubar=no ,location=no, scrollbars=no, resizable=no, width=" + width + ", height=" + height + ", top=" + (screen.height/2 - height/2) + ", left=" + (screen.width/2 - width/2) + "\"");
}
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}
function myFadeBack()
{
var flashMovie=getFlashMovieObject("FlashID");
flashMovie.TPlay("_level0.fadeanimation");
}
</script>
<script type="text/javascript">
window.onfocus=myFadeBack()
</script>
</head>
<body onfocus="myFadeBack()">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8.0.35.0"
WIDTH="100%" HEIGHT="1550" id="FlashID" ALIGN="">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="index.swf" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="bgcolor" value="#1E1B15" />
<embed src="index.swf" swliveconnect="true" wmode=opaque quality="high" scale="noscale" salign="lt" bgcolor="#1E1B15" width="100%" height="1550" NAME="FlashID" ALIGN="" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</BODY>
</HTML>
the correct way of calling it is
<script type="text/javascript">
window.onfocus=myFadeBack; // replace the event handler
</script>
</head>
and remove it from here:
<body onfocus="myFadeBack()">
<script type="text/javascript">
window.onfocus=myFadeBack;
</script>
</head>
and remove it from here:
<body onfocus="myFadeBack()">
ASKER
Thanks mplungjan, however it still does not work in Internet Explorer. Here is a link:
http://www.lukeheise.com/test5/index17.html
and below is the full code:
Thanks.
http://www.lukeheise.com/test5/index17.html
and below is the full code:
Thanks.
<!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/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
object {
width: 100%;
height: 1550px;
display: block;
outline: none;
}
</style>
<script language="JavaScript">
function Launch(page, width, height) {
OpenWin = this.open(page, "kirupa", "toolbar=no, menubar=no ,location=no, scrollbars=no, resizable=no, width=" + width + ", height=" + height + ", top=" + (screen.height/2 - height/2) + ", left=" + (screen.width/2 - width/2) + "\"");
}
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}
function myFadeBack()
{
var flashMovie=getFlashMovieObject("FlashID");
flashMovie.TPlay("_level0.fadeanimation");
}
</script>
<script type="text/javascript">
window.onfocus=myFadeBack;
</script>
</head>
<body>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8.0.35.0"
WIDTH="100%" HEIGHT="1550" id="FlashID" ALIGN="">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="index.swf" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="bgcolor" value="#1E1B15" />
<embed src="index.swf" swliveconnect="true" wmode=opaque quality="high" scale="noscale" salign="lt" bgcolor="#1E1B15" width="100%" height="1550" NAME="FlashID" ALIGN="" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</BODY>
</HTML>
Seems the onfocus does not trigger at all so the swf in the parent window has the focus at all times
I tried this:
window.onfocus=function(){ alert('foc ussed')}
and it really does not trigger
I suggest you do
<body onBeforeUnload="if (opener && !opener.closed && opener.myFadeBack) opener.myFadeBack()"
in the child window
I tried this:
window.onfocus=function(){
and it really does not trigger
I suggest you do
<body onBeforeUnload="if (opener && !opener.closed && opener.myFadeBack) opener.myFadeBack()"
in the child window
ASKER
There are 2 problems with onBeforeUnload.
1) The function isn't triggered if you leave the pop up window open and click back to the main window. Some users will click back to the main window without closing the popup.
2) The function is triggered when the url of the pop up window changes, not just when it is closed. Some of my pop up windows contain navigation with multiple html pages inside. This is problematic because I don't want the parent window to unfade until it is active.
I have gone down this road before and it didn't work out very well. I thought a better solution would be something like onFocus but it seems to have it's fair share of problems too.
Any more ideas? Surely there must be a work around for Internet Explorer since it works fine in the other browsers.
Thanks.
1) The function isn't triggered if you leave the pop up window open and click back to the main window. Some users will click back to the main window without closing the popup.
2) The function is triggered when the url of the pop up window changes, not just when it is closed. Some of my pop up windows contain navigation with multiple html pages inside. This is problematic because I don't want the parent window to unfade until it is active.
I have gone down this road before and it didn't work out very well. I thought a better solution would be something like onFocus but it seems to have it's fair share of problems too.
Any more ideas? Surely there must be a work around for Internet Explorer since it works fine in the other browsers.
Thanks.
trigger window.focus() from your swf onfocus
ASKER
Are you familiar with Flash? Can you elaborate? I'm guessing it should be something like:
getURL("javascript:window. onfocus=my FadeBack") ;
... but I doubt that's right.
Thanks.
getURL("javascript:window.
... but I doubt that's right.
Thanks.
Perhaps
getURL("javascript:swf.blu r(); window.focus()");
or similar
getURL("javascript:swf.blu
or similar
ASKER
Will this work with the above html, or do I need to make some further changes?
Also, should I put that code on a loop? I'm not sure what exactly it does.
Thanks.
Also, should I put that code on a loop? I'm not sure what exactly it does.
Thanks.
I do not do AS so it was just a suggestion. Others can most likely tell you where to call this. In some focus event in the flash. The swf. should likely be replaced with document.getElementById('i d of your flash object')
ASKER
Thanks mplungjan. I tried what you said but unfortunately could not get it working. This is harder than I thought it would be, so I've put the point value up to 500. I'm open to html/javascript and Flash solutions. Maybe there's a way inside Flash to detect whether the stage has focus or not. I'm using Actionscript 2.0 so keep that in mind.
Thanks.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
when the focus is on page.. you will get an alert focus and then you minimize the window to lose focus you will get a alert blur..
you can even try using window.onfocus, this will trigger when the window is in focus..
Open in new window