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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...