Jump to content

TUniURLFrame: how to fire OnAjaxEvent


steve589

Recommended Posts

Hi,

I cannot figure out how to fire the OnAjaxEvent from JS-code within the loaded page.

ajaxRequest can be called with "parent.ajaxRequest", but I cannot determine the first parameter "sender"

 

I tried:

  - parent.ajaxRequest(this, "ClickEvent", [ "param0=a", "param1=b" ]);

  - parent.ajaxRequest(O3C, "ClickEvent", [ "param0=a", "param1=b" ]);  // where "O3C" is the JS-name of the UniURLFrame (added via code on startup)

  - tried to get a reference to the UniURLFrame-control with:

      - var x = parent.getElementById("O3C");       // x is null

      - var x = parent.getElementById("O3C_id");  // x is null

nothing works.

 

Can anybody help please?

best regards

steve

 

Link to comment
Share on other sites

in MainForm there is only one UniURLFrame, then:

 

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
    UniURLFrame1.HTML.Text := 
        '<script type="text/javascript">' +
        '   document.addEventListener("click", function(e) { ' +
        '       parent.ajaxRequest(' + UniURLFrame1.JSName + ', "ClickEvent", [ "param0=a", "param1=b" ]);' +
        '   })' +
        '</script>' +
        '<br>' +
        'click here' +
        '<br>';
end;
 
// this is never called:
procedure TMainForm.UniURLFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings);
begin
    ShowMessage(Params.Values['param0'] + ' - ' + Params.Values['param1']);
end;
Link to comment
Share on other sites

Sorry, maybe I do not understand the issue completely, but try this:

UniURLFrame1.HTML.Text :=
        '<script type="text/javascript">' +
        '   document.addEventListener("click", function(e) { ' +
        '       parent.ajaxRequest(parent.' + UniURLFrame1.JSName + ', "ClickEvent", [ "param0=a", "param1=b" ]);' +
        '   })' +
        '</script>' +
        '<br>' +
        'click here' +
        '<br>';
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...