I am trying to open a modal jquery dialog using jquery 1.4 and jquery-ui-1.8rc3.custom.js
The dialog opens up with no issues, in all browsers, but in IE 7 and 6, after the dialog opens up, the window scrolls itself to the buttom... I tried scrolling the window up back to the modal position but is very inconsistent. was using the following line of code after opening up the modal
window.scrollTo($('#selector').dialog('option', 'position')[0],$('#selector').dialog('option', 'position')[1]);
One weird thing I am noticing is that after I open the modal, the page becomes huge... as if some extra things adds up on the bottom .... and it eventually scrolls to the bottom. Any idea why this could be hapenning
in html
<div id="selector">
</div>
in document.ready
$('#selector').dialog({
bgiframe: true,
autoOpen: false,
width: 100,
height: 100,
modal: true,
position: 'top'
});
in js
$('#selector').dialog('open');
I was struggling with this issue too. I didn't use any theming so I didn't have this important CSS property:
I added this to my CSS file and all works fine now:
I had this problem because I was assigning a class to the dialog that in my stylesheet was setting:
which was overriding the:
needed by the dialog.
Basically, make certain the .ui-dialog class has:
and the window shouldn't scroll to the bottom of the page and the extra vertical space won't be added to the body.
I had similar issue and this is how I resolved. Its similar to @bassim solution, but with a little different flavor of it.
I had the same anchor tag and used "$(#anchor-element).click(function(){..}. Below is the code snippet -
In jsp -
In javascript -
This did the trick and resolved the issue. Thank you for rest in this page who gave good pointers and helped to resolve the issue. Kudos team.
Looks like you are missing the
#
in your selector:that might be why the window is scrolling to the left top corner.
Edit: I was just looking at the documentation and
.dialog('option','position')
default value iscenter
.So you could get text or numbers returned using the position option and
window.scrollTo()
requires numbers. So try this instead:I have had a similar situation where the dialog was opening where it should on the page, but the user was redirected to the bottom of the page. Basically, I forgot to include the appropriate css to match the jQuery UI JavaScript library. By doing this everything was ok. I imagine it's something like that, where there are styles set on elements on the jQuery css that are not set in your own css.
To debug the problem so I didn't have to include the whole jQuery UI css, I made two identical pages, one using the jQuery UI css and one not and just checked what was different in the css via Firebug on Firefox and added these styles to my css.
Hope it helps. Mag
If you're using an anchor tag like below to trigger the dialog
you'll want to add a
return false;
to theonclick
attribute:This prevents the page reloading to anchor
#
which causes it to jump to the top.