File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -123,10 +123,32 @@ function makeInterface()
123123 evaluateButton . innerHTML = 'Activate' ;
124124 evaluateButton . className = 'buttonStyle001' ;
125125 evaluateButton . style . marginLeft = '200px' ;
126+
126127 evaluateButton . onclick = function ( )
127128 {
128- eval ( ge ( 'htmlInput' ) . value ) ;
129+ // Grab the raw text from the input
130+ let rawCode = ge ( 'htmlInput' ) . value ;
131+
132+ try
133+ {
134+ // Wrap the text in an anonymous function and execute it
135+ let result = new Function ( rawCode ) ( ) ;
136+
137+ // Optional: Do something with the result if the user used 'return'
138+ if ( result !== undefined )
139+ {
140+ console . log ( "Result: " , result ) ;
141+ // ge('outputDiv').innerHTML = result; // Uncomment if you have an output div!
142+ }
143+ }
144+ catch ( error )
145+ {
146+ // If they try to type HTML like <h1>Hello</h1>, it will fail safely here
147+ console . error ( "Syntax Error: " , error . message ) ;
148+ // alert("Syntax Error: " + error.message);
149+ }
129150 } ;
151+
130152 buttonRowContainer . append ( evaluateButton ) ;
131153
132154 //-//
You can’t perform that action at this time.
0 commit comments