Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI Dialog - when opened IE7 Browser moves instantly to the bottom of the page

i have been working on a new .net MVC site and have integrated some of the awesome jquery UI components.

ive been testing it in IE8, FF, opera and Chrome and all looks well. Once I test in IE7, surprisingly its the dialogs that are causing a problem.

basically what’s happening is that one you user clicks to open a dialog the page will scroll immediately to the bottom of the page. This is especially bad if the page is quite long.

this only happens in IE7 (and probably 6 but im not even going there!).

I have spend a few hours reading forums and it seems im not the only one.

I have created a dirty hack which im not keen on but it does work.

onclick="SignIn();  <% if(ModelHelperClass.CheckForOldIEVersion() == true) Response.Write("window.scrollTo(0, 0);"); %> return false;">

has anyone else had this issue and resolved it without resorting to dirty hacks ?

im using jquery-ui-1.8.custom.min.js and jquery-1.4.2.min.js

any help is most appreciated

Truegilly

Update---

hello, thanks for the response -

at the top of my page i have this declaration...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

i am including these files....

<link href="/Scripts/css/blitzer/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/Scripts/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="/Scripts/jquery-ui-1.8.1.custom.min.js" ></script>

here is my signin function - the other dialogs are pretty similar

// Sign in to the site
function SignIn() 
{
    $("#SignIn").dialog({
        bgiframe: true,
        modal: true,
        resizable: false,
        buttons: {

            'Sign In': function () {

                // the username and password
                var Username = $("#Username").val();
                var Password = $("#Password").val();

                var dataString = 'Username=' + Username + '&Password=' + Password;

                // AJAX here....

                // when the user clicks sign in, the form is submitted                
                //$("#SignInForm").submit();
            },
            Cancel: function () {
                $(this).dialog('close');
            }
        }
    });
}

as i say, it works fine in all browsers except IE7

like image 762
JGilmartin Avatar asked Feb 27 '23 22:02

JGilmartin


2 Answers

I had the same issue with IE7 and was using the latest version of jquery and didn't have any stray commas.

The fix turned out to be easy - a simple addition to the CSS. Adding .ui-dialog{ position: absolute; overflow:hidden } fixes it in IE7.

like image 163
Voodoo Avatar answered May 01 '23 14:05

Voodoo


Does the dialog use position: fixed? IE7 honors that only when in standards mode, but in quirks mode, it inserts such a dialog in the normal page flow, causing the rest of the page to move down.

Therefore, we should double-check, if you're really in standards mode:

  1. The Doctype declaration must be the absolutely first thing in the document (there must not be any comment or anything above it!)
  2. I would test with <!doctype html>, because it works very well to put IE7 (and all modern browsers) in standards mode, and it's harder to make a typing mistake.
like image 43
Chris Lercher Avatar answered May 01 '23 14:05

Chris Lercher