sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    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.
    • onidarbeO Offline
      onidarbe
      last edited by

      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
      • tt_suT Offline
        tt_su
        last edited by

        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
        • TIGT Offline
          TIG Moderator
          last edited by

              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
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            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
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              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
              • onidarbeO Offline
                onidarbe
                last edited by

                Thanks again!

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

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  @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

                    @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
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement