WebDialog - execute_script outside of add_action_callback?
-
Is using execute_script outside of an add_action_callback block allowed?
My code isn't working unless I do this, but if that's the case, then how do I send information to JavaScript without JavaScript asking for it?
i.e.
This doesn't work:webDiag = UI;;WebDialog.new(...) webDiag.set_html(...) webDiag.show() webDiag.execute_script("document.getElementById('myID').value = 'abc'")But this does:
webDiag = UI;;WebDialog.new(...) webDiag.set_html(...) webDiag.add_action_callback('update') { |web_dialog, params| web_dialog.execute_script("document.getElementById('myID').value = 'abc'") } webDiag.show() # Then JavaScript sends "update" back to Ruby... -
@draftomatic said:
Is using execute_script outside of an add_action_callback block allowed?
Yea, should be. Is that your actual test code that doesn't function? Or is it a representation of another script?
Are you calling
webDiag.execute_scriptimmediately afterwebDiag.show()?
In which case that is your problem, the webdialog has not manage to initiate yet.
What I do is create a load callback, then in the javascript hook into the event that triggers when the DOM has loaded and send a message back to Ruby for the load callback. Then I do the Ruby initiation stuff from there. -
@thomthom said:
@draftomatic said:
Is using execute_script outside of an add_action_callback block allowed?
In which case that is your problem, the webdialog has not manage to initiate yet.
What I do is create a load callback, then in the javascript hook into the event that triggers when the DOM has loaded and send a message back to Ruby for the load callback. Then I do the Ruby initiation stuff from there.Cool thanks, I'll try that.
Follow-up question: Does WebDialog DOM stay loaded when you use WebDialog.close() and then WebDialog.show()? Or do I need to wait again?
-
@draftomatic said:
Follow-up question: Does WebDialog DOM stay loaded when you use WebDialog.close() and then WebDialog.show()? Or do I need to wait again?
Good question. I don't know.
However, this can differ from Windows and OSX. As it does with the loading of the HTML.
From this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=23445@unknownuser said:
On Windows, the HTML document appear to be created when you call
dialog.show. If you attach an event towindow.onloadwhich send a command back to ruby to print"Hello World"in the console you'll see"Hello World"printed as you call.show. But on OSX it seems that the HTML document is created as you use.set_fileor.set_html- before calling.show. -
@thomthom said:
From this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=23445
Thanks a ton, thomthom - that thread just cured about 16 of my headaches (99 more to go!). The API documentation on WebDialogs is way too minimal...
-
Another tip which I might not have mentioned in that article, I find using a javascript framework (like jQuery) takes the pain out of the cross-compatibility JS issues.
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