Centering/Positioning a WebDialog at Load
-
This is a How-To demonstrating one way of positioning a WebDialog at the time it is first shown.
The ruby file:
w=UI;;WebDialog.new f = File.dirname(__FILE__) + "/w.html" w.set_file( f ) w.add_action_callback("move") { |d, a| xy, wh = a.split(";") x, y = xy.split(",") x = x.to_i y = y.to_i w, h = wh.split(",") w = w.to_i h = h.to_i d.set_position((x - w)/2, (y - h)/2) } w.showThe html file:
<html> <head> <script> function move_to_center() { window.location = "skp;move@" + screen.width + "," + screen.height + ";" + document.body.offsetWidth + "," + document.body.offsetHeight; } </script> </head> <body onLoad="move_to_center()"> Hi </body> </html>Another way is to execute a script in the dialog's show method:
w.show { w.execute_script("move_to_center()") }You then eliminate the need for the "onLoad" in the html body tag.
-
Hey Jim. Is there a question here, or are you posting how to do it?
-
Heh, it's supposed to be a how-to in reponse to this question.
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