WebDialog vs. Win7/IE10 problem
-
Dear sir:
I faced a problem with win7/IE10 combination. In my project, there is a need to get large string from a WebDialog. I know get_element_value should be used. However, on my win7 machine with IE10, get_element_value always return nil. I've tried using META information to force IE version from 7~10 but still in vain. The same program works with error on a Mac/Safari combination.
I'm looking forward to suggestions, thank you!Regards,
Lendle Tseng -
Sounds like you're not providing the correct ID name to the INPUT element.
Got a sample snippet that fails?
-
Thanks for the reply. The id/name of the input element is correct since the same program runs fine on a Mac/Safari environment. Below is the code snippet:
HTML:
<html> <head> <meta http-equiv="X-UA-Compatible" content="IE=7"/> </head> <script type="text/javascript"> function test1(){ document.getElementById("data1").value="123456"; window.location.href="skp;ruby_messagebox@"; } </script> <body> <a href="javascript:test1()">12345</a> <input type="hidden" id="data1" name="data1" value="123">123456</input> </body> </html>
Ruby:
tool_menu.add_item("HelloWorld Tool") { dlg = UI;;WebDialog.new("Show Sketchup.com", true, "ShowSketchUpDotCom", 739, 641, 150, 150, true); dlg.add_action_callback("ruby_messagebox") {|dialog1, params| UI.messagebox(dialog1.get_element_value("data1")) } dlg.set_url "http://localhost;8080/SketchupWeb/" dlg.show UI.messagebox(dialog1.get_element_value("data1")) }
Thank you!
Regards,
Lendle Tseng -
@thomthom said:
Sounds like you're not providing the correct ID name to the INPUT element.
Got a sample snippet that fails?
Dear sir, thanks for reply.
Th ID/Name of the input element is correct and the program works on Mac/Safari. -
Just for the record, don't use UI.messagebox for debugging. Sometimes it fails silently.
-
@jolran said:
Just for the record, don't use UI.messagebox for debugging. Sometimes it fails silently.
Dear sir:
Thanks for the reply. The UI.messagebox part does not fail. It just display an empty string.
By the way, the program works well on Mac/Safari. It just fails on Win7/IE10.Regards,
Lendle Tseng -
After you call webdialog.show the HTML content isn't necessarily ready.
I think that there are differences between OSX and Windows when it prepares the content. If I remember right, under OSX the HTML and DOM seem to be prepared as you use .set_html, .set_file or .set_url. Under windows it's done first when you call .show.
What you need to do is set up a callback from JS when the DOM is ready to notify the webdialog - then after that you can pull data from the webdialog.
I wrote about it in the Lost Manual: https://github.com/thomthom/sketchup-webdialogs-the-lost-manual/wiki/window.onload
I should add an example of how to wait for the DOM to be ready.
Javascript - Assuming you use jQuery
$(document).ready(function() { window.location = 'skp;Window_Ready'; } );
WebDialog:
webdialog = UI;;WebDialog.new webdialog.add_action_callback('Window_Ready') { |wd, params| wd.get_element_value('data1') } webdialog.show
-
As Thomthom said, a webdialog is created asynchronously because it could take time (at least for programmers, this is much valuable time). That means Ruby should not wait until the webdialog is visible, but it continues immediately with the next line of code. That is the reason why the Ruby API uses code blocks (
add_action_callback("action"){}
orshow{}
). The last one is known to be buggy. The best practice is to call a callback after the body of the html file (when the complete DOM is loaded).Offtopic: I recently noticed that modal webdialogs in the Windows version of SketchUp seem to be synchronous and stop executing Ruby code until the dialog is closed. I wouldn't rely on it, but it can be helpful for (unit) testing.
-
Yes, modal webdialogs under Windows are working as modal windows should. For some odd reason it's not working as a modal window under OSX.
Advertisement