Domanda

The data returned by the callback for appAPI.contextMenu is currently only the following:

  • pageUrl
  • linkUrl
  • selectedText
  • srcUrl

There doesn't seem like there's a way to tell what was actualy right clicked on, only a little information about it. I could for example search all images and find the one with the matching srcUrl, but what if the same image appears multiple times?

I could try catching right click events in extension.js and try to match them with context menu events, but this seems quite round about.

What's the expected method to find the selected element (after receiving the event in the page)?

Lets say for example I want to be able to right click an image and display:none it.

È stato utile?

Soluzione

Currently, the Crossrider platform does not support the feature you require and I think your workaround is reasonable. However, I have forwarded your suggestion to the Crossrider development team, who will consider it for future releases.

[Disclosure: I am a Crossrider employee]

Altri suggerimenti

As a workaround, this actually seems quite reliable although I haven't tested much. TBH I was expecting coherency issues:

//in extension.js (background.js just forward context menu events)
var lastRightClicked = null;
window.addEventListener("contextmenu", function(e) { //I guess a mousedown event would work here too
    lastRightClicked = e.target;
}, true);

appAPI.message.addListener({channel:"contextmenu"}, function(message) {
    if (message.menuitem == "Hide")
        lastRightClicked.style.display = "none";
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top