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

    Webdialog problem

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 6 Posters 830 Views 6 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.
    • P Offline
      Pout
      last edited by

      I have a webdialog set up like this:

      • Reads an external html file
      • Initialized at the beginning of the script (not shown)
      • some parts in the html are div of which i change the innerHTML by execute_script in ruby

      Now this all worked well. The innerHTML of the div was updated each time.
      That innerHTML is always created in ruby and then placed on the correct place in the existing html container.

      Now to one of those html i have added a (dynamic created) hyperlink which calls a javascript function. This function calls a action_callback in ruby.
      This all works ok, the action callback is executed and the action itself to.

      This is how the div is populated:

      htmlbegin="<table width=\"500\" border=\"0\" cellpadding=\"0\" cellspacing=\"5\"><tr><td width=\"50%\" height=\"20\" valign=\"top\"><span class=\"style1\">aaa</span></td><td width=\"20%\" valign=\"top\"><span class=\"style1\">bbb</span></td><td width=\"15%\" valign=\"top\"><span class=\"style1\">ccc</span></td><td width=\"15%\" valign=\"top\"><span class=\"style1\">ddd</span></td></tr>"
      	htmlend="</table>"
      	innerhtml=""
      	#for each active object create a line in the html
      	$xdactive.each {|a,b|
      		row="<tr><td width=\"50%\" height=\"20\" valign=\"top\"><span class=\"style1\"><a href=\"javascript&#058;_showInSU("+a.to_s+");\">"+a.to_s+"</a></span></td><td width=\"20%\" valign=\"top\"><span class=\"style1\">"+b+"</span></td><td width=\"15%\" valign=\"top\"><span class=\"style1\">ccc</span></td><td width=\"15%\" valign=\"top\"><span class=\"style1\">ddd</span></td></tr>"
      		innerhtml<<row
      	}
      	totalhtml=htmlbegin<<innerhtml<<htmlend
      	command = "_activeobjects('#{totalhtml}')"
      	$xdwindow.execute_script(command)
      

      in javascript

      function _activeobjects(activelist) {
      	document.getElementById("activeobjects").innerHTML=activelist;
        	}
      function _showInSU(thearray) {
      	SUIDs=thearray;
      	//send the SUID array to Sketchup
      	query = 'skp;_showInSU@' + SUIDs;
      	window.location.href = query;
      

      After this has been executed (i have clicked on a link in the webdialog and the action was executed in ruby), all javascript/ruby communication is stopped. None of the javascripts works anymore. I get no error, no bug splat.

      Any ideas?

      1 Reply Last reply Reply Quote 0
      • T Offline
        talig
        last edited by

        Pout - can you post the Ruby code?
        I have a webdialog with a few JS stuff and I get repeated callbacks just fine... Maybe the problem is elsewhere?

        Avatar: all rights reserved to Bryan Eppihimer

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by

          Sometimes an uncaught JS exception can silently kill the works. Surround all your JS code with try{} catch{} blocks and see what happens.

          1 Reply Last reply Reply Quote 0
          • T Offline
            talig
            last edited by

            Todd is right. Haven't thought of that...
            If it's possible, you should debug the JS separately with the error pane in Firefox (or FireBug plugin, if you so fancy).
            That will help focusing on the problem.

            • Tali

            Avatar: all rights reserved to Bryan Eppihimer

            1 Reply Last reply Reply Quote 0
            • chrisglasierC Offline
              chrisglasier
              last edited by

              If you don't mind me repeating, if you are using a webdialog do as much as possible in its html file.

              I also suggest you generate html using something like this:

              
              for(a=0; a<abcdArray.length; a++){
              
              obj=document.createElement(tagname)
              document.getDocumentById(parentId).appendChild(obj)
              
              with(obj){
              innerHTML = abcdArray[a]
              
              with(style){
              ...
              } }
              
              }
              
              

              If still troublesome you can use try .. catch(e) to find which iteration causes the problem.

              As far as possible just use ruby for the connection (e.g. opening the dialog) and any action in the SU interface.

              Hope this helps,

              Chris

              With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

              1 Reply Last reply Reply Quote 0
              • scottliningerS Offline
                scottlininger
                last edited by

                Talig,

                In the code for the dynamic link that you're generating, are you using a "#" as the href? If so, try changing it to "javascript:;" and see if that helps. For example, if you have something like this...

                <a href="#" onclick="doSomething()">Link</a>
                

                Change it to this...

                <a href="javascript&#058;;" onclick="doSomething()">Link</a>
                

                Or even better, get rid of the link entirely...

                <span onclick="doSomething()">Link</span>
                

                I've seen a problem similar to what you're describing that was caused by something like the above.

                Cheers,

                • Scott Lininger
                  SketchUp Software Engineer
                  Have you visited the Ruby API Docs?
                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @unknownuser said:

                  Talig,

                  In the code for the dynamic link that you're generating, are you using a "#" as the href? If so, try changing it to "javascript:;" and see if that helps. For example, if you have something like this...

                  <a href="#" onclick="doSomething()">Link</a>
                  

                  Change it to this...

                  <a href="javascript&#058;;" onclick="doSomething()">Link</a>
                  

                  Or even better, get rid of the link entirely...

                  <span onclick="doSomething()">Link</span>
                  

                  I've seen a problem similar to what you're describing that was caused by something like the above.

                  Cheers,

                  Or, make sure the onclick() event returns false. That will prevent the website from trying to follow the URL in the HREF.

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    talig
                    last edited by

                    Scott,
                    I'm not the one who posted the question πŸ˜„

                    • Tali

                    Avatar: all rights reserved to Bryan Eppihimer

                    1 Reply Last reply Reply Quote 0
                    • P Offline
                      Pout
                      last edited by

                      Hey all, thanks for the support and answers.

                      I have made a workarround by just generating and regenerating my html script all from in ruby itself.
                      So there is no external html file used anymore. This off course is not the best way (like chris says it's better to do all in html) but for now, it will do. I'll see if i can solve this in the near future. It it to be expected that the way i use now is slower or less stable?

                      Scott, the href contains javascript:doSomething();
                      Maybe if i drop the href and use the span it will solve.
                      I'll keep you posted once i get into this again.

                      Regards and thanks!

                      1 Reply Last reply Reply Quote 0
                      • scottliningerS Offline
                        scottlininger
                        last edited by

                        @pout said:

                        I have made a workarround by just generating and regenerating my html script all from in ruby itself.
                        So there is no external html file used anymore. This off course is not the best way (like chris says it's better to do all in html) but for now, it will do.

                        I dunno, the advantage is that your script install has fewer files. Unless you're regenerating an extremely large set of HTML or doing it a lot, I think you'd be fine with that approach.

                        @unknownuser said:

                        Scott, the href contains javascript:doSomething();
                        Maybe if i drop the href and use the span it will solve.
                        I'll keep you posted once i get into this again.

                        In that case, I think that if doSomething() returns false, as Thom suggested, then the problem should go away. Sounds like you found a solution in any case! πŸ˜„

                        Cheers,

                        • Scott Lininger
                          SketchUp Software Engineer
                          Have you visited the Ruby API Docs?
                        1 Reply Last reply Reply Quote 0
                        • P Offline
                          Pout
                          last edited by

                          on the first point: the set of html is indeed not so small and it is regenerated a lot of times πŸ˜•
                          so in the near future i intend to try getting as much as possible back into the external html again.

                          I'll keep you posted on progress.
                          Thx!

                          1 Reply Last reply Reply Quote 0
                          • chrisglasierC Offline
                            chrisglasier
                            last edited by

                            As you know I am keen to promote the use of webdialogs. One significant reason is that html files can contain links to the world. Afterall we are told by such gurus as Kevin Kelly and Tim Berners-Lee that data linking is the future of the World Wide Web.

                            @pout said:

                            on the first point: the set of html is indeed not so small and it is regenerated a lot of times

                            So I want to post this:

                            Mechanisms should not be designed to suit the size of the current task. They should be made for types of tasks to be reusable with different variables and conditions. Then you and any collaborators will appreciate their existence in the future. Using html markup in quotes in either ruby or javascript files is contrary to this approach. Using tables for layout should be avoided.

                            If you like I am willing to help you do it this way but you will need to show more of what you have achieved so far.

                            Chris

                            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                            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