Jump to content

TUniURLFrame client event 'frameload' firing when form loads


SantoshGnostice

Recommended Posts

Hi

 

I have a form with a frame inside which is initially empty and at a later point I set a URL to the frame to load a page. I need some JS to be run after the frame has loaded the page. For this I have setup a handler under ClientEvents -> ExtEvents -> frameload as shown below:

function frameload(sender, frame, eOpts)
{
   alert('Viewer loaded!');
} 

However I am finding that this event is fired twice. Once when the application is loaded. And again later when I set a URL to the frame and the frame is done loading the page. The second firing is fine but I don't understand why it's firing the first time when nothing is loaded in the frame.

 
Apprecitiate the help!
Link to comment
Share on other sites

@mohammad my situation is a bit different. Let me try to explain with a simple example. I have a main form on which I have a button and a TUniURLFrame (which is basically an iframe element in HTML). When the user clicks the button I load another website inside the TUniURLFrame. I want to be notified when the iframe has finished loading the external website. For this I am trying to use the TUniURLFrame's ClientEvents -> ExtEvents -> frameload event which should fire after the external website is done loading completely inside the iframe. There is no other way for me to find out the completion of the load. This all works fine except for the issue where when my application main form is loaded the TUniURLFrame's frameload event is being fired though there is nothing for it to load (it's URL property is empty when the app starts).

Link to comment
Share on other sites

Hi,

 

If I understand you correctly, you can try to use OnFrameLoaded event on the server side instead of "function frameload",

for example:

procedure TMainForm.UniURLFrame1FrameLoaded(Sender: TObject);
begin
  if (Sender as TUniURLFrame).URL<>'' then
    // your code
 
end;

Best regards,

Link to comment
Share on other sites

Hi,

 

If I understand you correctly, you can try to use OnFrameLoaded event on the server side instead of "function frameload",

for example:

procedure TMainForm.UniURLFrame1FrameLoaded(Sender: TObject);
begin
  if (Sender as TUniURLFrame).URL<>'' then
    // your code
 
end;

Best regards,

I need to run some JS in response to the frame load hence the reason for me to use the client-side event.

 

I seem to be getting answers suggesting workarounds which I appreciate but unfortunately those won't work for my need. I believe the errant behavior is due to a bug either in UniGUI or in Ext JS.

Link to comment
Share on other sites

Ok, we will check this

 

I need to run some JS in response to the frame load hence the reason for me to use the client-side event.

procedure TMainForm.UniURLFrame1FrameLoaded(Sender: TObject);
begin
  if (Sender as TUniURLFrame).URL<>'' then
    UniSession.AddJS('alert("Viewer loaded!")'); 
 
end;
Link to comment
Share on other sites

BTW your suggestion and code prompted me to do a workaround for this. Now I am checking the iframe's "src" attribute and ignoring the first event.

function frameload(sender, frame, eOpts)
{
   // For some unknown reason (bug?) this event is called when the parent form loads and
   // the frame is still empty. So ignore it if the src is blank.
   var frameDivId = MainForm.UniURLFrame1.id;
   var frame = $('#' + frameDivId + ' iframe');
   var src = frame.attr('src');
   if (src === 'about:blank') {
      return;
   }

   // ...
}
Link to comment
Share on other sites

  • 2 years later...
On 10/12/2017 at 1:06 PM, mhmda said:

The best way is to use js and check for existing element 'id' I always use an element in the bottom of the page to be sure that the page is fully loaded.

How can i get element by id inside in iframe ( iframe URL has a different domain ). Thanks

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...