• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Probem Using UI:WebDialog and Javascript

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 4 Posters 621 Views 4 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.
  • C Offline
    curator
    last edited by 25 Aug 2014, 12:21

    Hi all,

    I have some problem here. I created the follwing minimal example as an HTML File:

    <script>
    
    function callJavaScript(i_Value) 
    {
    alert('hi')
    	var jsonString = '{ "foo"; 42, "bar"; 17 }';
    	var jsObject = JSON.parse( jsonString );
    	alert(jsObject["foo"])
    
    	var message = jsObject["foo"];
    	document.getElementById('output').innerHTML = message;
    
    alert(obj.count);
    }
    </script>
    <html>
    	<body onload = "callJavaScript('Update')">
    
    		<h3 id="output"></h3>
    	</body>
    </html>
    

    Wenn opening in a browser, it start by welcoming with 'hi' and prompts 42 afterwards. That makes no sense, but works as expected. However, if I now use sketchup to display that html file, e.g., like this:

    p_File = Sketchup.find_support_file("DEMO.html","Plugins")
    			p_Dialog = UI;;WebDialog.new("DEMO")
    			p_Dialog .set_file(p_File )
    			p_SettingsDialog.show
    

    That does not work anymore. The Dialog opens and greetings 'hi' still works, but the JSON stuff doesn't work anymore.

    Can anyone provide any help?

    kinds regards,
    curator

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 25 Aug 2014, 14:22

      seems to work as set html...

      html = %Q(<script>
       
      function callJavaScript(i_Value)
      {
      alert('hi')
         var jsonString = '{ "foo"; 42, "bar"; 17 }';
         var jsObject = JSON.parse( jsonString );
         alert(jsObject["foo"])
       
         var message = jsObject["foo"];
         document.getElementById('output').innerHTML = message;
       
      alert(obj.count);
      }
      </script>
      <html>
         <body onload = "callJavaScript('Update')">
       
            <h3 id="output"></h3>
         </body>
      </html>)
       
               p_Dialog = UI;;WebDialog.new("DEMO")
               p_Dialog.set_html(html)
               RUBY_PLATFORM =~ /(darwin)/ ? p_Dialog.show_modal ; p_Dialog.show()
      

      I'm on a mac, hence the show_modal

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 25 Aug 2014, 14:55

        FYI, everything should be inside the <HTML> </HTML> tags.

        Read ThomThom's Lost Manual for WebDialogs and the alternative to body.onload that works better with SKetchUp.
        https://github.com/thomthom/sketchup-webdialogs-the-lost-manual/wiki

        EDIT: Sorry, just looked, it is not in there. But I know it is in many replies Thomas gave in this forum on the same topic. Determine the status of when the document is ready.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • T Offline
          tt_su
          last edited by 25 Aug 2014, 17:25

          Yes, I use jQuery's ready event exclusively as it takes care of all cross browser compatibility.

          Not sure why you are seeing differences between set_html and set_file, but cleaning up the HTML to valid syntax would be the first step. All bets are off if the markup isn't valid - browsers try to recover very differently.

          1 Reply Last reply Reply Quote 0
          • T Offline
            tt_su
            last edited by 25 Aug 2014, 17:26

            By the way, what OS?

            1 Reply Last reply Reply Quote 0
            • C Offline
              curator
              last edited by 26 Aug 2014, 06:51

              Thanks very much, cleaning up html did the job. If its still of intereset, i use windows 7.

              Haven't seen my HTML mistake, so thanks again,
              curator

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

              Advertisement