LC Server / Innerhtml / JavaScript

Ralph DiMola rdimola at evergreeninfo.net
Wed Apr 15 11:24:43 EDT 2020


This took me a while to figure out. If anyone else needs this functionality this can save you a lot of searching and testing.

Problem:

1) You have a web page already loaded in the client browser with an empty <div>.
2) You insert html into the innerHTML of the <div> from an LC server callback.
3) The html has JavaScript.

The JavaScript will not be executed.

But if you insert this code you can make it work. This is an empty image with onLoad function.

Example of in-line code:

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="alert('test');this.parentNode.removeChild(this);" />

Or

Example to execute a page's existing JavaScript function:

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="myJavaScriptFunctionCall();this.parentNode.removeChild(this);" />

Just a little diddi I thought I'd pass on...

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net






More information about the use-livecode mailing list