OK:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Conforming HTML 4.01 Transitional Template</title>
<script type="text/javascript">
/* Block F5 refresh in frames © John Davenport Scheuer
* As first seen in http://www.dynamicdrive.com/forums/
* Username: jscheuer1 - This credit must remain for legal use */
function nof5(){
if(window.frames&&window.frames[0]){
window.frames[0].focus();
for (var i_tem = 0; i_tem < window.frames.length; i_tem++)
if(document.all&&document.body.filters)
window.frames[i_tem].document.onkeydown=new Function("var e=window.frames["+i_tem+"].event; if(e.keyCode==116){e.keyCode=0;return false;};");
else if(document.getElementById)
window.frames[i_tem].onkeypress=new Function("e","if(e.keyCode==116){e.preventDefault();e.stopPropagation();}")
}
}
</script>
</head>
<frameset onload="nof5();" cols = "25%, 25%,*">
<frame src ="black.htm" />
<frame src ="black.htm" />
<frame src ="black.htm" />
<noframes>
<body>
<!-- place alternative information for accessibility purposes here -->
</body>
</noframes>
</frameset>
</html>
Notes: Only tested with blank pages inside the frames. This will only work if the page showing through the frame is from the same domain as the top page or frameset. It works for frames in IE 6, FF 1.5.0.4, and Opera 9 - perhaps others. It will work for iframes in IE 6 and Opera 9, not FF. To use it on pages containing iframes, add this to the end of the page, just before the closing </body> tag:
Code:
<script type="text/javascript">
/* Block F5 refresh in frames © John Davenport Scheuer
* As first seen in http://www.dynamicdrive.com/forums/
* Username: jscheuer1 - This credit must remain for legal use */
if(window.frames&&window.frames[0]){
window.frames[0].focus();
for (var i_tem = 0; i_tem < window.frames.length; i_tem++)
if(document.all&&document.body.filters)
window.frames[i_tem].document.onkeydown=new Function("var e=window.frames["+i_tem+"].event; if(e.keyCode==116){e.keyCode=0;return false;};");
else if(document.getElementById)
window.frames[i_tem].onkeypress=new Function("e","if(e.keyCode==116){e.preventDefault();e.stopPropagation();}")
}
</script>
More Notes (added later): This can be used with FF for iframes but they must be initialized onload of their content. Example:
HTML Code:
<iframe onload="nof5();" src="../black.htm" width="300" height="300" scrolling="" frameborder="1"></iframe>
and, in this case the full function as shown in the first code block in this post must be used. Fortunately, this will still allow the script to work for IE and Opera. Additionally, I found that your original script did not work in Opera, this version will and still works in IE and FF:
Code:
var asciiF5 = 116;
var bRet = true;
var msg='';
if(document.all&&document.body.filters){
document.onkeydown = onKeyPress;
}else if (document.layers || document.getElementById){
document.onkeypress = onKeyPress;
}
function onKeyPress(evt) {
window.status = '';
var oEvent = evt? evt : window.event;
var nKeyCode = oEvent.keyCode ? oEvent.keyCode :
oEvent.which ? oEvent.which :
void 0;
var bIsFunctionKey = false;
if(oEvent.charCode == null || oEvent.charCode == 0){
//alert(oEvent.keyCode);
bIsFunctionKey = (nKeyCode == asciiF5)
}
if(bIsFunctionKey){
bRet = false;
try{
oEvent.returnValue = false;
oEvent.cancelBubble = true;
if(document.all){ //IE
oEvent.keyCode = 0;
}else{ //NS
oEvent.preventDefault();
oEvent.stopPropagation();
}
window.status = msg;
}catch(ex){
alert(ex);
}
}
return bRet;
}
Both the frame script I wrote and the above can be used on the same page (only worth doing on a page with an iframe), if desired.
Bookmarks