Модераторы: Sardar, Aliance
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Вызов меню при правом клике, правый клик по таблице 
:(
    Опции темы
sugee
Дата 12.6.2005, 20:52 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 423
Регистрация: 12.6.2005

Репутация: нет
Всего: 4



Привет всем!
Бьюсь над этой проблемой уже два дня: на странице расположено несколько таблиц. Нужно чтобы при правом клике мышью
на таблице выскакивало меню. Нашел скрипт где меню появляется
при правом клике в любой точке экрана что нужно сделать чтобы оно появлялось именно при щелчке по таблице?

Код
Код

 <html>
<head>
<style>
.skin0{

position:absolute;

width:200px;

border:2px solid black;

background-color:menu;

font-family:Verdana;

line-height:20px;

cursor:default;

visibility:hidden;

}

.skin1{

cursor: default;

font: menutext;

position: absolute;

width: 165px;

background-color: menu;

border: 1 solid buttonface;

visibility:hidden;

border: 2 outset buttonhighlight;

}

.menuitems{

padding-left:15px;

padding-right:10px;

}

-->

</style>

<script language="JavaScript1.2">

//set the skin of the menu (0 or 1, with 1 rendering a default Windows menu like skin)

var menuskin=1

//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar

var display_url=0

 

function showmenuie5(){

//Find out how close the mouse is to the corner of the window

var rightedge=document.body.clientWidth-event.clientX

var bottomedge=document.body.clientHeight-event.clientY

//if the horizontal distance isn't enough to accomodate the width of the context menu

if (rightedge<ie5menu.offsetWidth)

//move the horizontal position of the menu to the left by it's width

ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth

else

//position the horizontal position of the menu where the mouse was clicked

ie5menu.style.left=document.body.scrollLeft+event.clientX

//same concept with the vertical position

if (bottomedge<ie5menu.offsetHeight)

ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight

else

ie5menu.style.top=document.body.scrollTop+event.clientY

ie5menu.style.visibility="visible"

return false

}

function hidemenuie5(){

ie5menu.style.visibility="hidden"

}

function highlightie5(){

if (event.srcElement.className=="menuitems"){

event.srcElement.style.backgroundColor="highlight"

event.srcElement.style.color="white"

if (display_url==1)

window.status=event.srcElement.url

}

}

function lowlightie5(){

if (event.srcElement.className=="menuitems"){

event.srcElement.style.backgroundColor=""

event.srcElement.style.color="black"

window.status=''

}

}

function jumptoie5(){

if (event.srcElement.className=="menuitems"){

if (event.srcElement.getAttribute("target")!=null)

window.open(event.srcElement.url,event.srcElement.getAttribute("target"))

else

window.location=event.srcElement.url

}

}

</script>


</head>
<body>
<!--[if IE]>

<div id="ie5menu" class="skin0" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">
<div class="menuitems" url="http://www.informer.ru">
    Главная</div>
  <div class="menuitems" url="http://nov52.narod.ru/index.htm">
    Скрипты</div>
  <div class="menuitems" url="http://nov52.narod.ru/index.htm">
    Бесплатное в сети</div>
  <hr>
  <div class="menuitems" url="mailto:[email protected]">
    Пишите письма</div>

</div>

<![endif]-->

<script language="JavaScript1.2">

if (document.all&&window.print){

if (menuskin==0)

ie5menu.className="skin0"

else

ie5menu.className="skin1"

document.oncontextmenu=showmenuie5

document.body.onclick=hidemenuie5

}

</script>

</body>
</html>
 


Или может кто кинет ссылочку на готовый скрипт по теме!?


PM MAIL   Вверх
sugee
Дата 12.6.2005, 22:31 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 423
Регистрация: 12.6.2005

Репутация: нет
Всего: 4



Нет я не говорю что кто-то дорлжен ковыряться в этом скрипте
Но может кто-нибудь сталкивался с такой проблемой?
При щелчке на таблице(допустим внутри тега div) правой кнопкой мыши
выскакивает менюшка - всего то и делов... Очень нужно!!!
PM MAIL   Вверх
Ciber SLasH
Дата 12.6.2005, 22:58 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Участник Клуба
Сообщений: 1813
Регистрация: 9.11.2004
Где: С.-Петербург

Репутация: 24
Всего: 67



Ну так и переделывай свой скрипт, только событие onContextMenu к таблице прикрути:
Код

<table cellspacing=5 cellpadding=5 align=center bgcolor=lime border=1 onContextMenu="alert('Хорошь давить на правый батон крысы !!')">
<tr><td>111111111111111111111<td>222222222222222222222222
<tr><td>333333333333333333333<td>444444444444444444444444
</table>

Добавлено @ 23:02
Вот побыстрому навоял:
Код

<html>
<head>
<style>
.skin0{
    position: absolute;
    width: 200px;
    border: 2px solid black;
    background-color: menu;
    font-family: Verdana;
    line-height: 20px;
    cursor: default;
    visibility: hidden;
}
.skin1{
    cursor: default;
    font: menutext;
    position: absolute;
    width: 165px;
    background-color: menu;
    border: 1 solid buttonface;
    visibility: hidden;
    border: 2 outset buttonhighlight;
}
.menuitems{
    padding-left: 15px;
    padding-right: 10px;
}
</style>
<script language="JavaScript">
//set the skin of the menu (0 or 1, with 1 rendering a default Windows menu like skin)
var menuskin=1
//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0

function showmenuie5() {
//Find out how close the mouse is to the corner of the window
var rightedge = document.body.clientWidth - event.clientX
var bottomedge = document.body.clientHeight - event.clientY

  //if the horizontal distance isn't enough to accomodate the width of the context menu
  if (rightedge < ie5menu.offsetWidth)
    //move the horizontal position of the menu to the left by it's width
    ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth
  else
    //position the horizontal position of the menu where the mouse was clicked
    ie5menu.style.left = document.body.scrollLeft + event.clientX
  //same concept with the vertical position
  if (bottomedge < ie5menu.offsetHeight)
    ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight
  else
    ie5menu.style.top = document.body.scrollTop + event.clientY
  ie5menu.style.visibility = "visible"
return false
}

function hidemenuie5() {
  ie5menu.style.visibility = "hidden"
}

function highlightie5() {
  if (event.srcElement.className == "menuitems") {
    event.srcElement.style.backgroundColor = "highlight"
    event.srcElement.style.color = "white"
    if (display_url == 1)
      window.status = event.srcElement.url
  }
}

function lowlightie5() {
  if (event.srcElement.className == "menuitems") {
    event.srcElement.style.backgroundColor = ""
    event.srcElement.style.color = "black"
    window.status = ''
  }
}

function jumptoie5() {
  if (event.srcElement.className == "menuitems") {
    if (event.srcElement.getAttribute("target") != null)
      window.open(event.srcElement.url, event.srcElement.getAttribute("target"))
    else
      window.location = event.srcElement.url
  }
}
</script>
</head>

<body>
<!--[if IE]>
<div id="ie5menu" class="skin0" onMouseover="highlightie5()" onMouseout="lowlightie5()" onClick="jumptoie5()">
  <div class="menuitems" url="http://www.informer.ru">Главная</div>
  <div class="menuitems" url="http://nov52.narod.ru/index.htm">Скрипты</div>
  <div class="menuitems" url="http://nov52.narod.ru/index.htm">Бесплатное в сети</div>
  <hr>
  <div class="menuitems" url="mailto:[email protected]">Пишите письма</div>
</div>
<![endif]-->
<table id=tab cellspacing=5 cellpadding=5 align=center bgcolor=lime border=1>
<tr><td>111111111111111111111<td>222222222222222222222222
<tr><td>333333333333333333333<td>444444444444444444444444
</table>
<script language="JavaScript">
if (document.all && window.print) {
  if (menuskin == 0)
    ie5menu.className = "skin0"
  else
    ie5menu.className = "skin1"
  document.getElementById('tab').oncontextmenu = showmenuie5
  document.body.onclick = hidemenuie5
}
</script>
</body>
</html>

PM   Вверх
sugee
Дата 13.6.2005, 02:08 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 423
Регистрация: 12.6.2005

Репутация: нет
Всего: 4



Вот спасибо! А я тут с горя чуть свой вариант не написал
Только у меня меню вызывается наведением мыши а мне нужно именно правой кнопкой. В принципе если подумать то тут тоже можно сделать так чтобы при наведении мыши на таблицу вызываллась функция-обработчик правой кнопки, но чето я не смог


Код

<html><head>
<style type="text/css">
.menu{position:absolute; font:12px arial; background-color:yellow;visibility:hidden}
.tbl{position:absolute; top:100px; left:100px}
</style>

<script>
ismBrowser=(document.getElementById)?true:false;

function openmenu(Elem,nextPosition) {
menuObj=(ismBrowser)?document.getElementById(Elem).style:eval("document."+Elem);
  if(openmenu.arguments.length==1) {
 nextPosition=(parseInt(menuObj.top)==-90);
  }
menuObj.top=(ismBrowser)?nextPosition+"px":nextPosition;
menuObj.visibility="visible";
}

function closemenu(Elem,nextPosition) {
menuObj.top=(ismBrowser)?nextPosition+"px":nextPosition;
menuObj.visibility="hidden";
}
</script>

</head>
<body>
<span class="tbl" onmouseover="openmenu('lnkMenu', -5)" onmouseout="closemenu('lnkMenu',-90)">
<table width=100 height=50 bgcolor="blue">
<tr><td>&nbsp</td></tr>
</table>
<div id="lnkMenu"  class="menu">
<a href="javascript:window.open()">open</a><br>
<a href="javascript:window.open()">open</a><br>
<a href="javascript:window.open()">open</a><br>
<a href="javascript:window.open()">open</a><br>
</div>
</span>
</body></html>

PM MAIL   Вверх
Ciber SLasH
Дата 13.6.2005, 02:16 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
***


Профиль
Группа: Участник Клуба
Сообщений: 1813
Регистрация: 9.11.2004
Где: С.-Петербург

Репутация: 24
Всего: 67



Вместо:
Цитата
onmouseover="openmenu('lnkMenu', -5)" onmouseout="closemenu('lnkMenu',-90)"

пиши:
Цитата
onContextMenu="openmenu(<твои параметры>)"


Я ведь писал:
Цитата(Ciber @ 12.6.2005, 23:58)
только событие onContextMenu к таблице прикрути

Ты видно читаешь по диагонали. Внимательней будь.

PM   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Форум для вопросов, которые имеются в справочниках, но их поиск вызвал затруднения, или для разработчика требуется совет или просьба отыскать ошибку. Напоминаем: 1) чётко формулируйте вопрос, 2) приведите пример того, что уже сделано, 3) укажите явно, нужен работающий пример или подсказка о том, где найти информацию.
 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | JavaScript: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.0468 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.