JScript innerHTML not working in WebDialog !
-
Why does this produce an error in a WebDialog, but not if I run the HTML/JS in my Chrome browser?
msg = %{ <html> <table> <tbody id="test"> <tr> <td>xxx</td> </tr> </tbody> </table> <script type="text/javascript"> tbody.innerHTML = "<tr> <td>yyy</td> </tr>"; </script> </html> } win = UI;;WebDialog.new( "" ) win.set_html( msg ) win.show
Same problem using: document.getElementById("test").innerHTML
-
You should compare against the render engine that the WebDialog uses: IE under Windows and Safari/WebKit under OSX.
Not sure if all HTML engines allow innerHTML under all doc types.
-
msg = %{ <html><head><script type="text/javascript"> function swapper() { var value1=document.getElementById("test1").innerText ; var value2=document.getElementById("test2").innerText ; document.getElementById("test1").innerText =value2; document.getElementById("test2").innerText =value1; } </script></head><body> <table> <tbody> <tr> <td id="test1">xxx</td> </tr> <tr> <td id="test2">yyy</td> </tr> </tbody> </table> <br> <input type="button" value="Swapper" onClick="this.blur; swapper();" /> </body> </html> } win = UI;;WebDialog.new( "" ) win.set_html( msg ) win.show{}
Ought to work ? I added a button for fun
I think you are over thinking it... and attempting something that can't be done !I use things like this all of the time - e.g. to translate parts of my dialog's text into other locale languages... avoiding having different language versions...
It's set in the dlg'sself.populate()
method which it calls in its 'show{ ... }
' block...
@dlg.show{ self.populate() } ... def self.populate() ... @dlg.execute_script("document.getElementById('enabled').innerHTML='#{ENABLED}';") ... end
WhereENABLED
is a Constant set at the start of the script read from a locale file... -
It is always good to read the documentation for each browser.
In the case of MSIE:
http://msdn.microsoft.com/en-us/library/ms533897(v=vs.85).aspx
which says:
@unknownuser said:The innerHTML property is read-only on the col, colGroup, frameSet, html, head, style, table, tBody, tFoot, tHead, title, and tr objects.
-
Also, because of security issues, use innerText whenever you can, rather than innerHTML.
-
Thanks again!
So Sketchup uses IE instead of Chrome, although I uninstalled IE? strange
-
@onidarbe said:
So Sketchup uses IE instead of Chrome, although I uninstalled IE? strange
You cannot completely uninstall IE. You may have uninstalled the front-end, but the IE engine is embedded deep into the OS. Help files (chm files) are using the HTML engine, HTA files are also using it. And the embedded HTML IE webcontrol is more conservative in terms of compatibility, which is why you need to use META tags to force WebDialogs to use the very latest IE engine.
And because so many things use the system HTML engine I recommend you keep IE up to date, even if you use a different browser. You can never remove it 100% anyway. The "uninstaller" is just a shim to please the public (and EU anti-trust).
-
@tt_su said:
@onidarbe said:
So Sketchup uses IE instead of Chrome, although I uninstalled IE? strange
You cannot completely uninstall IE. You may have uninstalled the front-end, but the IE engine is embedded deep into the OS. Help files (chm files) are using the HTML engine, HTA files are also using it. And the embedded HTML IE webcontrol is more conservative in terms of compatibility, which is why you need to use META tags to force WebDialogs to use the very latest IE engine.
And because so many things use the system HTML engine I recommend you keep IE up to date, even if you use a different browser. You can never remove it 100% anyway. The "uninstaller" is just a shim to please the public (and EU anti-trust).
For Mac users, the equivalent statement is that SketchUp uses the WebKit Framework, not Safari. Just as on Windows, your choice of browser has no effect on what SketchUp's WebDIalogs do.
Advertisement