Closed Bug 426357 Opened 16 years ago Closed 15 years ago

<body onload="javascript:window.focus();"> Doesn't receive focus every time link is loaded.

Categories

(Firefox :: General, defect)

PowerPC
macOS
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: kalyke, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13

<body onload="javascript:window.focus();"> In photo gallery the pop up receives focus first time loaded and if a different thumbnail is clicked the pop up doesn't receive focus again. The popup should receive focus everytime a thumbnail is clicked. 

Reproducible: Always

Steps to Reproduce:
1. Click on photo thumbnail (Opens popup with larger image)
2. Click back on main page and click a different image thumbnail 
Actual Results:  
No focus given to popup, when image changed

Expected Results:  
The popup window should be given focus everytime a photo thumbnail is clicked and the popup window is reloaded.

Works in IE and Safari.
Summary: <body onload="javascript:window.focus();"> Doesn't receive focus every time link is clicked. → <body onload="javascript:window.focus();"> Doesn't receive focus every time link is loaded.
In Options > Content > Advanced, do you have "Allow scripts to: raise or lower windows" checked?
Okay, great to know but, the point of self.focus or window.focus is to bring the window to the front with code and not require the user to change browser settings. Is there any other way around it? I have a site with all it's portfolio galleries loading into a the same self focusing window. I need the page to focus. Any ideas?
You should be able to call window.focus() on any window during an onclick event.  Try doing that instead of using onload.
Yup, That did it. :) Thanks.
Ooops. not yet. I had my browser settings to "Allow scripts to raise or lower windows" I'm a bit of a novice with code. 
This is my text linked code 
<a href="javascript:;" onclick="MM_openBrWindow('arch_e_gal.html','','')">Exteriors</a>

do i want to add 'focus' here or within the Javascript 'MM_openBrWindow' function in my header?
Either place should be fine; both happen "during" the click event as far as Firefox is concerned.
Okay... I found the workaround that is working for me. So far it works in Firefox 3(Mac and PC), IE 7, Safari 3(Mac), Opera 9.01(Mac), Flock, Netscape(7 Mac), Camino... It consistently loads a new browser window and brings it to focus in all above browsers (excluding IE when "open new window in a new tab" is selected in options). I position and size the new window within each page. What I really wanted fix - focus - and this does it.

HEAD CODE
var newwindow;
function MM_openBrWindow(url,winName,features)
{
	newwindow=window.open(url,'name','toolbar=no,status=no,scrollbars=yes,resizable=yes');
	if (window.focus) {newwindow.focus()}
}

BODY CODE
<a href="test.html" onClick="MM_openBrWindow(this.href); return false;"> open page</a>	

This site really helped http://www.yourhtmlsource.com/javascript/popupwindows.html
We're not going to make <body onload="javascript:window.focus();"> work for everyone, since it's often an annoyance, just like popup ads.  Glad to know the fix for bug 355482 is working for you, allowing you to move the focus() call and get the effect you want.
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.