Probem Using UI:WebDialog and Javascript
-
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.showThat 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 -
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
-
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/wikiEDIT: 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.
-
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.
-
By the way, what OS?
-
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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement