• Login
sketchucation logo sketchucation
  • Login
๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

JScript innerHTML not working in WebDialog !

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 5 Posters 874 Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    onidarbe
    last edited by 22 Jan 2014, 11:38

    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

    1 Reply Last reply Reply Quote 0
    • T Offline
      tt_su
      last edited by 22 Jan 2014, 14:36

      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.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 22 Jan 2014, 15:01

            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's self.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
        Where ENABLED is a Constant set at the start of the script read from a locale file...

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 22 Jan 2014, 16:15

          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.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 22 Jan 2014, 16:17

            Also, because of security issues, use innerText whenever you can, rather than innerHTML.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • O Offline
              onidarbe
              last edited by 22 Jan 2014, 16:44

              Thanks again!

              So Sketchup uses IE instead of Chrome, although I uninstalled IE? strange

              1 Reply Last reply Reply Quote 0
              • T Offline
                tt_su
                last edited by 22 Jan 2014, 16:49

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

                1 Reply Last reply Reply Quote 0
                • S Offline
                  slbaumgartner
                  last edited by 23 Jan 2014, 14:02

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

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    1/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement