Webdialog problem
-
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:_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?
-
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? -
Sometimes an uncaught JS exception can silently kill the works. Surround all your JS code with try{} catch{} blocks and see what happens.
-
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
-
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
-
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:;" 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,
-
@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:;" 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.
-
Scott,
I'm not the one who posted the question- Tali
-
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!
-
@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,
-
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! -
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
Advertisement