禁止右击Div (infobox)。如何启用它

时间:2022-04-14 22:56:08

I am using the Infobox plugin for Google Maps V3 API. http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html

我正在为谷歌地图V3 API使用Infobox插件。http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html

Problem: When I rightclick on the infobox div, nothing happens. Same goes for any div that is the child of the parent infobox div. However I have an input box that contains some text that I want to be able to select and rightclick copy.

问题:当我右击infobox div时,什么都没有发生。对于任何属于父infobox div的div,都是一样的。但是,我有一个输入框,其中包含一些文本,我希望能够选择并右键单击copy。

How can this be done if I cannot rightclick on it? More importantly, how can I enable right clicking?

如果我不能右击它,怎么做呢?更重要的是,如何启用右击?

Example

例子

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/infobox-basic.html


JS Code Does not work

JS代码不起作用。

var infoboxOptions = {
    content: boxText,
    disableAutoPan: true,
    maxWidth: 0,
    pixelOffset: new google.maps.Size(0, 0),
    zIndex: null,
    infoBoxClearance: new google.maps.Size(5, 5),
    closeBoxURL: '',
    isHidden: true,
    pane: "floatPane",
    enableEventPropagation: false,
    contextmenu: true
    };

4 个解决方案

#1


7  

I modifed the infobox.js code to get it working.

我modifed细节。js代码使其工作。

Changed this:

改变:

    this.contextListener_ = google.maps.event.addDomListener(this.div_, "contextmenu", ignoreHandler);

to this:

:

    this.contextListener_ = google.maps.event.addDomListener(this.div_, "contextmenu", cancelHandler);

DISCLAIMER: this may have other ill effects I am not aware of as I didn't test it thoroughly, but it works in my case.

免责声明:这可能有我没有注意到的其他副作用,因为我没有对它进行彻底的测试,但它在我的情况下是有效的。

#2


1  

Just add "contextmenu: true" to the set of options

只要在选项集中添加“contextmenu: true”即可

#3


1  

I pulled this from the infobox.js source:

我把这个从信息箱里拿出来。js来源:

  • @property {boolean} enableEventPropagation Propagate mousedown, click, dblclick,
  • @property {boolean} enableEventPropagation传播mousedown,点击,dblclick,
  • and contextmenu events in the InfoBox (default is false to mimic the behavior
  • 以及InfoBox中的contextmenu事件(默认情况下,模拟该行为是假的
  • of a google.maps.InfoWindow). Set this property to true if the InfoBox
  • google.maps.InfoWindow)。如果设置为InfoBox,则将此属性设置为true
  • is being used as a map label. iPhone note: This property setting has no effect; events are
  • 被用作地图标签。注:此属性设置无效;事件是
  • always propagated.
  • 总是传播。

Looks like setting your enableEventPropagation property to true should do the trick!

看起来,将enableEventPropagation属性设置为true应该很有用!

#4


0  

Try this code. This is very short code and very useful code. And this is Javascript not jQuery so it will work for all browsers.

试试这个代码。这是非常短的代码和非常有用的代码。这是Javascript而不是jQuery,所以它适用于所有浏览器。

To disable right click

禁用右键

function yourFunction() {
  alert("Not allowed");
}

document.oncontextmenu = new Function("yourFunction();return false;");

To Renable Right Click

Renable右单击

document.oncontextmenu = new Function("return true;");

#1


7  

I modifed the infobox.js code to get it working.

我modifed细节。js代码使其工作。

Changed this:

改变:

    this.contextListener_ = google.maps.event.addDomListener(this.div_, "contextmenu", ignoreHandler);

to this:

:

    this.contextListener_ = google.maps.event.addDomListener(this.div_, "contextmenu", cancelHandler);

DISCLAIMER: this may have other ill effects I am not aware of as I didn't test it thoroughly, but it works in my case.

免责声明:这可能有我没有注意到的其他副作用,因为我没有对它进行彻底的测试,但它在我的情况下是有效的。

#2


1  

Just add "contextmenu: true" to the set of options

只要在选项集中添加“contextmenu: true”即可

#3


1  

I pulled this from the infobox.js source:

我把这个从信息箱里拿出来。js来源:

  • @property {boolean} enableEventPropagation Propagate mousedown, click, dblclick,
  • @property {boolean} enableEventPropagation传播mousedown,点击,dblclick,
  • and contextmenu events in the InfoBox (default is false to mimic the behavior
  • 以及InfoBox中的contextmenu事件(默认情况下,模拟该行为是假的
  • of a google.maps.InfoWindow). Set this property to true if the InfoBox
  • google.maps.InfoWindow)。如果设置为InfoBox,则将此属性设置为true
  • is being used as a map label. iPhone note: This property setting has no effect; events are
  • 被用作地图标签。注:此属性设置无效;事件是
  • always propagated.
  • 总是传播。

Looks like setting your enableEventPropagation property to true should do the trick!

看起来,将enableEventPropagation属性设置为true应该很有用!

#4


0  

Try this code. This is very short code and very useful code. And this is Javascript not jQuery so it will work for all browsers.

试试这个代码。这是非常短的代码和非常有用的代码。这是Javascript而不是jQuery,所以它适用于所有浏览器。

To disable right click

禁用右键

function yourFunction() {
  alert("Not allowed");
}

document.oncontextmenu = new Function("yourFunction();return false;");

To Renable Right Click

Renable右单击

document.oncontextmenu = new Function("return true;");