Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI dialog width & height based on screen width & height

Currently (jQuery 1.4.4 and UI 1.8.8) I used the following to set a dialog's properties: (I'm trying to set the dialog to be 180px less than the height and width of the screen.)

$("#dialog").dialog({ 
            bgiframe: true,
            position: 'center',
            width: $(window).width()-180,
            height: $(window).height()-180,
            title: ititle,
            modal: true,
            buttons: { "Close": function() { $(this).dialog("destroy"); }}
});

The above works fine in FF but in IE 8 it fails.

Is this the right way to set width and height or should I be doing something differently?

like image 580
Jason Avatar asked Jan 18 '11 16:01

Jason


People also ask

How to set jQuery dialog width?

Syntax: $( ". selector" ). dialog({ width : 120 });

How make jQuery ui dialog responsive?

Below is how I achieved a responsive jQuery UI Dialog. To do this, I added a new option to the config - fluid: true , which says to make the dialog responsive. I then catch the resize and dialog open events, to change the max-width of the dialog on the fly, and reposition the dialog.

How can I fix the position of dialog box in jQuery?

dialog({ autoOpen: true, title: user_str, height: 200, stack: true, sticky: true //uses ui dialog extension to keep it fixed });

How do you check if jQuery dialog is initialized?

dialog( { ... } ); Then check for the class when needed: if ($("selector"). hasClass("initialized")) { ... }


2 Answers

This worked for me in IE8:

var winW = $(window).width() - 180;
var winH = $(window).height() - 180;

$( "#dialog" ).dialog({
    autoOpen: false,
    height: winH,
    width: winW,
    modal: true
});

You'll need this at the top of your page though

<!DOCTYPE html>
like image 147
usr-bin-drinking Avatar answered Sep 20 '22 12:09

usr-bin-drinking


You probably need to specify the DOCTYPE and use standards mode for it to work correctly.

like image 35
Gregg Avatar answered Sep 22 '22 12:09

Gregg