2
votes

I'm developing a Firefox extension. I want to see if the selected text is in a editable area like in a WEBMAIL, GOOGLE DOCS, etc. If it is then some items in the context menu will be available in order to modify that text. As i happened to find these editable textareas are located inside a certain iframe.

After contextmenu happens how do i check if the selected text that was right clicked is inside an iframe (therefore editable) so i can make the context menu items visible?

window.addEventListener("contextmenu", function(e) { 
      var menu = document.getElementById('crypt');

      if(x)
      { menu.hidden=false; }
      else
      { menu.hidden=true;  }



}, false);

Thank you, Alex!

1

1 Answers

0
votes
window.addEventListener("contextmenu", function(e) { 
    var menu_crypt = document.getElementById('crypt');
    var menu_decrypt = document.getElementById('decrypt');

    if( (e.target.nodeName == 'U')        || 
        (e.target.nodeName == 'I')        ||
        (e.target.nodeName == 'B')          )     
    {
        if (   (e.target.parentNode.nodeName == 'SPAN') ||
               (e.target.parentNode.nodeName == 'HTML') ||
               (e.target.parentNode.nodeName == 'BODY')   )
               {
                    //alert(e.target.nodeName);
                    //alert(e.target.parentNode.nodeName);
                    menu_crypt.hidden = false;
                    menu_decrypt.hidden = false;
               }            
    }
    else if (   (e.target.nodeName == 'SPAN')     ||
                (e.target.nodeName == 'HTML')     ||
                (e.target.nodeName == 'BODY')     ||
                (e.target.nodeName == 'TEXTAREA')   ) 
        {   
            menu_crypt.hidden = false;
            menu_decrypt.hidden = false;        
        }
    else if (   (e.target.nodeName == 'INPUT')  && (e.target.type!='submit')    )
        {
            //alert(e.target.type);
            //alert(e.target.nodeName);
            menu_crypt.hidden = false;
            menu_decrypt.hidden = false;        
        }


    else {      
        menu_crypt.hidden = true;
        menu_decrypt.hidden = true;
    }

}, false);

Never mind. I just managed to solve the issue another way!

The selected text's nodeName is either a Underline, Italic, Bold, Span. I allowed these nodes and filtered the ones that might masquerade as editable text.

Hope this will help someone else!