{Framesaufbau mit JavaScript}

Sicher kennt ihr die Probleme die bei der Benutzung von Frames auftreten. Wird eine Unterseite alleine aufgerufen fehlt das komplette Frames-Layout. Dies kann zum Beispiel durch eine Suchmaschine passieren, die auch Unterseiten deiner Homepage in die Datenbank einträgt.
Abhilfe schafft da ein kleines browserunabhängiges JavaSkript (getestet mit Internet Explorer 4 und Netscape Navigator 4) das innerhalb des <head>-Bereichs in jeder Unterseite steht. Es überprüft ob die Unterseite in einem Frame (Rahmen) steht und falls das nicht der Fall ist wird das Frameset zur Navigation usw. erstellt.

Das Skript für diese Seite sieht so aus :

<script language="JavaScript">
<!---
function is_msie() {
return (navigator.appName == "Microsoft Internet Explorer");}
function Framing(){
if (this.document == top.document ||
top.location.host != this.location.host) {
var pathprefix = location.protocol + '//'
+ location.host
+ location.pathname.substring(0,
location.pathname.lastIndexOf('/')+1);
var doctitle = document.title;
document.clear();
document.open("text/html");
document.writeln('<html>\n<head><title>' +doctitle+
'</title></head>');
document.writeln('
<frameset cols="150,*" framespacing="0" border="false" frameborder="0" noresize>'+
'<frame src="'+pathprefix+'
inhalt2.htm" name=inhalt scrolling="no" noresize>'+
'<frame src="'+top.location.href+'" name=Hauptframe >'+
'</frameset></html>');
document.close();
return true;
}
return false;
}
function msieFraming() {
if (is_msie()) {
if (Framing()) {
window.setTimeout('top.frames["Hauptframe"].location.href = '+
'"'+top.location.href+'";',10);
}}}
function netscFraming() {
if (!is_msie()) Framing();
}
msieFraming();
// --->
</script>

Die Einstellungen zum Frame sind orange gekennzeichnet und leicht zu ändern. Ihr könnt versuchen diese Seite einem neuen Fenster öffnen um das Skript zu testen.


© by WebmasterNETZ - http://www.web-art.de/webmasternetz