• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Kontext Menü

Status
Für weitere Antworten geschlossen.

Kack_Idol

Neues Mitglied
Hallo!

Ich möchte gerne ein Kontext Menü auf meiner Homepage haben so das der User wenn er Rechtsklickt ein Kontext Menü erscheint und nicht "zurück, vorwärts, hintergrund speichern unter..." etc.

Ich habe schonmal sowas auf einer Seite gesehen aber ich weiß jetzt nicht mehr wo sie ist kann mir den jemand verraten wie man sowas macht?


Vielen Dank im Vorraus!
 
Werbung:
Topa schrieb:
Sorry, aber ich weiß nicht was ein Kontext Menü ist..

dann musste ja hier auch net posten.

das wird mit js realisiert, meinst du sowas wie auf eselfilme.com?
kopier' dir das doch einfach...

Nils aka XraYSoLo
 
Werbung:
Ich rede von einem Menü ...

klick mal auf irgendeiner Webseite mit der rechten Maustaste!

Sofort erscheint ein Menü!

Hier ein beispiel:


kontext.jpg
 
Werbung:
Für alle die nicht wissen, was ein Context Menü ist:#

Es ist das Menü, was sich beim Rechtsklick öffnet.
Sowas habe ich irgedowauch schon mal gesehen, ich glaube sogar bei selfhtml. Ich bin mir aber nicht sicher.
 
Kack_Idol schrieb:
Ja ich weiß aber ich will ja das ändern!!
Das kannst du nicht ändern, weil dazu müsstest du das Browser-Programm ändern. :lol:

Was aber mit JavaScript geht, wie seby richtig erkannt hat, ist das abfangen des Rechtsklick. Darauf müsstest du eine Div mit "position:absolute" ausgeben, in der die Links sind. Hierfür bräuchtest du dann noch eine Mouse-Out bzw. On-Klick Funktion, damit das Menü auch wieder verschwindet.

Nur die ganze Arbeit ist umsonst, wenn der Besucher JavaScript deaktiviert hat. Was ja doch öfters vorkommt als man glaubt. ;)

Gruß
Hobbyuser
 
Werbung:
hobbyuser schrieb:
Nur die ganze Arbeit ist umsonst, wenn der Besucher JavaScript deaktiviert hat. Was ja doch öfters vorkommt als man glaubt. ;)
Meist werden nur Funktionen, die einen zu großen Eingriff in die gewohnte Arbeitsumgebung des Benutzers darstellen, unterbunden.
 
oh nein nicht immer ich habe auch mal sowas gemacht vor nem halben jahr und da war das bei jedem rechner kein prob
 
aus dem javascript codebook von addison-wesley:
Code:
kontextmenu.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Wie kann ich auf Klicks mit der rechten Maustaste reagieren?</title>
<style type="text/css">
#contextGeneral {
  position: absolute;
  visibility: hidden;
	border-bottom-width: 1px;
	border : groove #A9A9A9;
	font-size : 1em;
	letter-spacing : 1px;
	padding : 15px;
	background-color: #9CCEFF;
	layer-background-color: #FFCE63;
}

.description {
	border-color: #9CCEFF;
	border-bottom-width: 1px;
	border : groove #9CCEFF;
	font-size : 1em;
	letter-spacing : 1px;
	padding : 15px;
	background-color: #FFCE63;
	layer-background-color: #FFCE63;
}

</style>
<script language="JavaScript" src=".lib.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
function showgeneral(evt){
  var e = evt || window.event;
  var mouseButton = e.which || e.button;
  var contextMenu = getLayerRef("contextGeneral");

  if(mouseButton == 3 || mouseButton == 2) {
    setPosition(contextMenu, getMouseXY(e));
    setVisibility(contextMenu, true);
  } else {
    setVisibility(contextMenu, false);
  }
  return false;
}


function init(){

  if(self.document.captureEvents){
    self.document.captureEvents(Event.MOUSEDOWN );
    window.onresize = function(){self.location.reload();}
  }

  self.document.onmousedown = showgeneral;
  if(document.all)
    document.oncontextmenu = function(){return false};

}
window.onload=init;

</script>
</head>

<body>
<div class="description" id="desc">
  Ein eigenes Kontext Men&uuml; f&uuml;r das Dokument.
</div>
<div id="contextGeneral">
  [url="#"]rot[/url]

  [url="#"]wei&szlig;[/url]

  [url="#"]blau[/url]

  [url="#"]lime[/url]

</div>
</body>
</html>
Code:
lib.js

/**
 * oft genutzte Objekte in DHTML:
 *  Coord
 *  Canvas
 * oft genutzt Funktionen in DHTML
 *  @return LayerReference getLayerRef(String ID)
 *  @return void setPosition(LayerReference objLayer, Coord coords)  
 *  @return void setVisibility(LayerReference objLayer, boolean visible)
 *  @return Coord getMouseXY(evt)
 *  @return void setVisibility4DivByPrefix(prefix, visible)
 */

// Objekte
function Coord(x, y){
  this.x = (!x)?0:x;
  this.y = (!y)?0:y;
  
  this.toString = objToString;
  this.equals = equalsCoord;
}

function Canvas(x, y, width, height){
  this.width = (!width)?0:width;
  this.height = (!height)?0:height;
  
  this.Coord = Coord;
  this.Coord(x, y);
  
  this.equalsCoord = this.equals;
  this.equals = equalsCanvas;
}

function objToString(){
  var ret = "{";
  for(p in this ){
    if (typeof this[p] == "function" || typeof this[p] == "object") continue;
    if(ret.length > 1)
      ret += ",";
    ret += p + ":" + this[p];
  }
  return ret + "}";
}

function equalsCoord(/*Coord*/ c){
  return (this.x == c.x && this.y == c.y);
}
function equalsCanvas(/*Canvas*/ c){
  return ( this.equalsCoord == c.equalsCoord && this.width == c.width && this.height == c.height);
}

// Funktionen

function getLayerRef (id, document) {
  if (!document)
    document = window.document;
  if (document.layers) {
    for (var l = 0; l < document.layers.length; l++)
      if (document.layers[l].id == id)
        return document.layers[l];
    for (var l = 0; l < document.layers.length; l++) {
      var result = getLayerRef(id, document.layers[l].document);
      if (result)
        return result;
    }
    return null;
  }
  else if (document.all) {
    return document.all[id];
  }
  else if (document.getElementById) {
    return document.getElementById(id);
  } else {
    return null;
  }
}

function setPosition(objLayer, coords){

    if (document.layers) {
      objLayer.top = coords.y;
      objLayer.left = coords.x;
    } else if (window.opera) {
      objLayer.style.top = coords.y;
      objLayer.style.left = coords.x;
    } else if (document.all) {
      objLayer.style.top = coords.y;
      objLayer.style.pixelLeft = coords.x;
    } else if (document.getElementById) {
      objLayer.style.top = coords.y + 'px'; 
      objLayer.style.left = coords.x + 'px';
    }
}

function setPositionById(id, coords){
  var objLayer = getLayerRef(id);
  if(typeof objLayer == undefined) return;
  
  if (document.layers) {
    objLayer.top = coords.y;
    objLayer.left = coords.x;
  } else if (window.opera) {
    objLayer.style.top = coords.y;
    objLayer.style.left = coords.x;
  } else if (document.all) {
    objLayer.style.top = coords.y;
    objLayer.style.pixelLeft = coords.x;
  } else if (document.getElementById) {
    objLayer.style.top = coords.y + 'px'; 
    objLayer.style.left = coords.x + 'px';
  }
}


function setVisibility(objLayer, visible) {

  if(document.layers){
    objLayer.visibility  = 
        (visible == true) ? 'show' : 'hide';
  } else {
    objLayer.style.visibility = 
        (visible == true) ? 'visible' : 'hidden';
  }

}

function setVisibility4DivByPrefix(prefix, visible, d){
  if (!d)
    d = window.document;

  if(document.layers){
    for (var l = 0; l < d.layers.length; l++){
      if(d.layers[l].id.substr(0, prefix.length ) == prefix)
        setVisibility(d.layers[l], visible);
      setVisibility4DivByPrefix(prefix, 
                                visible, 
                                d.layers[l].document);
    }

  } else if(document.all) {

    var layers = document.all.tags("div"); 
    for(i=0; i < layers.length; i++) { 
      if(layers[i].id.substr(0, prefix.length ) == prefix )
        setVisibility(document.all.tags("div")[i], visible);
    }

  } else if(document.getElementsByTagName) {

    var layers = document.getElementsByTagName("div");
    for(i=0; i < layers.length; i++){
      if(layers[i].id.substr(0, prefix.length ) == prefix)
        setVisibility(layers[i], visible);
    }

  }
}

function getMouseXY(evt) {
  e = evt || window.event;
  if(!e) return null;
  
  if(document.layers) {
    return new Coord(e.pageX, e.pageY);
  }else if(window.opera){
    return new Coord(e.clientX, e.clientY);
  }else if(document.all ) {
    return new Coord(e.x + document.body.scrollLeft, e.y + document.body.scrollTop);
  }else if(document.getElementById) {
    return new Coord(e.pageX , e.pageY );
  }
}

function /*out: Coord*/ getLayerCoords( /*in: HTML-Object*/ objLayer ){
  var coords = new Coord();
  
  if (document.layers) {
    coords.y = objLayer.top;
    coords.x = objLayer.left;
  } else if ( window.opera ) {
    coords.y = objLayer.style.top;
    coords.x = objLayer.style.left;
  } else if (document.all) {
    o = objLayer;
    while(o.offsetParent) {
      coords.y += parseInt(o.offsetTop);
      coords.x += parseInt(o.offsetLeft);
      o = o.offsetParent;
    }
  } else if (document.getElementById) {
    coords.y = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue('top') ); 
    coords.x = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue("left") );
  }
 
  return coords;
}

function /*out: Coord*/ getLayerCoordsById( /*in: String*/ id ){
  var objLayer = getLayerRef(id);
  var coords = new Coord();
  
  if (document.layers) {
    coords.y = objLayer.top;
    coords.x = objLayer.left;
  } else if ( window.opera ) {
    coords.y = objLayer.style.top;
    coords.x = objLayer.style.left;
  } else if (document.all) {
    o = objLayer;
    while(o.offsetParent) {
      coords.y += parseInt(o.offsetTop);
      coords.x += parseInt(o.offsetLeft);
      o = o.offsetParent;
    }
  } else if (document.getElementById) {
    coords.y = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue('top') ); 
    coords.x = parseInt( document.defaultView.getComputedStyle(objLayer, '').getPropertyValue("left") );
  }
 
  return coords;
}
http://www.html-beispiel.de.vu/js/kontextmenu.html

dann brauchst du eigentlich nur noch eine rechtsklick-sperre für das normale kontextmenü.
 
Werbung:
ich habe auch nicht gesagt, dass du es gesagt hast, ich habe lediglich darauf hingewiesen :wink:

mfg
 
Werbung:
Status
Für weitere Antworten geschlossen.
Zurück
Oben