Categories | Question details Back To List | ||
DHTMLXWindows fails to execute script present in the HTML using attachHTMLString Hi, We are using DHTMLX suite Professional Edition. We use DHTMLX windows attachHTMLString to display HTML content generated using ajax call. The original dhtmlxwindows.js did not handle any javascripts present in the HTML. So we got a patch which handles javascripts in the HTML content and executes that script. The patch is the following: win.attachHTMLString = function(str) { that._attachContent(this, "str", str); var z=str.match(/<script[^>]*>[^\f]*?<\/script>/g)||[]; for (var i=0; i<z.length; i++){ var s=z[i].replace(/<([\/]{0,1})script[^>]*>/g,"") if (window.execScript) { if (s.length != 0) window.execScript(s); } else { window.eval(s); } } } We have an HTML code similar to the following: <html> <head> <script> <!-- function myFunc() { alert("My Func"); } myFunc(); --> </script> </head> <body > .... </body> </html> This HTML is a valid HTML and the run is any browser and it executes the function myFunc. But if we attach this HTML using the attachHTMLString function then the browser throws javascript syntax error and does not execute the script. The reason I think is the <!-- and --> tags in the script content and the attachHTMLString code does not handle that. Please help us solve this issue. Thanks Sudipta Answer posted by Alex (support) on Aug 20, 2009 01:49 Hello, there reason for the issue is that execScript and eval can not handle <!-- -->. You should delete them before calling these methods. |