Jump to content

HTMLFrame.HTML.Text script Loaded At Runtime '<canvas id="myCanvas"><script>function test()...</script>' How do I call test() from Delphi ?


andyhill

Recommended Posts

uniSession.AddJS('test();'); // FAILS test() not defined

If the script is loaded in the IDE it works !

There is lots of talk on the forum dealing with this problem but no clear answer that I can see - please advise - thanks

Link to comment
Share on other sites

If the function is not defined, it is not loaded.

Put the script in a textfile and load it, and it will work despite having commented lines. Or terminate those lines.

Dynamically loading a script as strings in code, including commented lines (starting with //) and not terminating them with CR/LF (chr(13)+chr(10)) will disable everything after the //, and functions will then not be loaded.

So if it works, it is loaded. If it does not work, it is not loaded.

 

If part of the script is "lost" due to commented lines, you will not get a warning in the console as that part is not loaded.

The browser just believes you have disabled the rest of the script. Checking for "undefined" or running the function, will tell you if it is loaded or not.

'function updateView()'+
      '{'+
      '  //canvas.width = MainForm.HTMLFrame.getWidth();'+  chr(13)+chr(10)+
      '  //canvas.height = MainForm.HTMLFrame.getHeight(); '+   chr(13)+chr(10)+
      '  canvas.width = 600;'+
      '  canvas.height = 360;'+
      '  drawScreen();'+
      '}'+

 

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