views:

143

answers:

2

I would like to know how I can maintain the scroll position when I open a jQuery dialog.

Here is the code I'm using to open my dialog:

<a class="link" onclick="openmyDialog();" href="#">Open a dialog</a>

And the function :

function openmyDialog()
{
    $("#dialog").dialog('destroy');
    $("#dialog").html("msg");
    $("#dialog").dialog(
    {
     buttons:
     {
     "Yes": function()
        {
         $(this).dialog("close");
        }
     },
     resizable: false,
     draggable: true,
     modal: true,
     title: 'Error'
    });
    return false;
}
A: 

Use <a href="javascript:void(0);"></a> instead of "#"?

meep
That fixes a symptom, but leaves the root cause (failure to cancel the default behavior). See Greg's answer for a simple way to accomplish the latter.
Shog9
+3  A: 

You're not returning your return value to the click handler properly:

onclick="return openmyDialog();"
Greg