Jump to content

<img Tag: Add RightClick Event without using the default "contextmenu" - Please Advise


andyhill

Recommended Posts

I have the following script displaying many images (id=00 ... 20):-

<img id="00" width="'+IntToStr(w)+'" height="'+IntToStr(h)+'" oncontextmenu="return false" ...

Please advise how I can add individual RightClick Events to each <img tag - Thanks in advance.

Link to comment
Share on other sites

2 hours ago, andyhill said:

<img id="00" width="'+IntToStr(w)+'" height="'+IntToStr(h)+'" oncontextmenu="return false" ...

Please advise how I can add individual RightClick Events to each <img tag

Hello,

Please explain in more detail. What do you want to achieve?

Link to comment
Share on other sites

7 hours ago, andyhill said:

25 to 50 <img tags inside a htmlframe, all need unique RightClick events

1. 

  public
    { Public declarations }
    ImgID: string;
  end;

2. UniHTMLFrame -> HTML

<img id="Image1" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png" alt="google" width="100" height="100" oncontextmenu="return false">

3. UniHTMLFrame -> ClientEvents -> ExtEvents ->

function afterrender(sender, eOpts)
{
    sender.getEl().dom.addEventListener(
        'mousedown', 
        function(e) { 
            if (e.target.tagName == 'IMG' && e.button == 2) {
                ajaxRequest(sender, '_contextmenu', ['imgId='+e.target.id, 'x=' + e.offsetX, 'y=' + e.offsetY])
            }
        }
    )
}

4. UniHTMLFrame -> OnAjaxEvent ->

procedure TMainForm.HTMLFrameAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
begin
  if EventName = '_contextmenu' then
  begin
    ImgID := Params.Values['imgId'];
    UniPopupMenu1.Popup(Params.Values['x'].ToInteger(), Params.Values['y'].ToInteger());
  end;

end;

...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...