I have an aspx page opened in a modal. On button click I need to close the current modal and open a new one or just open the new page in the same modal.

Any suggestions?

Below is my code:

function updateListItem(id,val) {

    var clientContext = args['context'];
    var oList = clientContext.get_web().get_lists().getByTitle('Weekly');

    this.oListItem = oList.getItemById(id);

    oListItem.set_item('SortOrder', val);

    clientContext.executeQueryAsync(Function.createDelegate(this,this.succeed), Function.createDelegate(this,this.onQueryFailed));


function succeed() {

    var options = SP.UI.$create_DialogOptions();
    options.width = 500;
    options.height = 250;
    options.url = dialogResult;

But it gives me this error:

SCRIPT5011: Can't execute code from a freed script


1 Answer 1


The best way to open a modal dialog in SharePoint 2013 is to use the built-in JavaScript function called "OpenPopUpPage". This was introduced in SP2010 and is used widely throughout SP2013.

To change the page being loaded within the modal dialog, you can then use a simple "window.location.href" function.


Opening a Modal Dialog

<a href="#" onclick="javascript:OpenPopUpPage('/Site/Lists/Weekly/Sorted.aspx', 'Weekly', 500, 250);">Open Dialog</a>

Changing What's in the Dialog

<a href="#" onclick="javascript:window.location.href('/Site/Lists/Weekly/Details.aspx');">View Details</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.