0

I have that url:

<a onClick="showDialog({$product['id']});">More Info...</a>

In Addition I have:

function showDialog(productID)
{
    $( "#dialog-modal_"+productID ).html( "<iframe src='index.php?act=showProduct&amp;id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
    $( "#dialog-modal_"+productID ).dialog({
    width: 810,
    height: 590,
    resizable: false,
    modal: true,
    open: function(event, ui)
    {
        event.preventDefault();
    }
    });
    container
        .dialog('option', 'title', 'Your Title')
        .dialog('option', 'buttons', {
            Close: function() {
                $(this).dialog('close');
            }
        })
        .dialog('open');

    var stateObj = { foo: "bar" };
    window.history.pushState(stateObj, "page 2", "{$info['siteurl']}/index.html#product-"+productID);

}

if I open it once it's working, but if I try once again, it is not opening. I need to find a way to "clear" the last dialog of the current ID. for different dialogs its working, but only once.

1 Answer 1

2

Inside the product loop:

<a href="javascript:" class="productOpener" data-id="{$product['id']}">more info...</a>

And your javascript:

$(".productOpener").click(function() {
    showDialog($(this).data("id"));
});

And modify your showDialog to just create the modal div when you need it:

function showDialog(productID) {
    var _modal = $("<div/>"); //add whatever styling you need
    _modal.html( "<iframe src='index.php?act=showProduct&amp;id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
    _modal.dialog({ ... });
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

why should i edit showDialog() as written? how does it make change?
Adding _modal dynamically was just a suggestion; without knowing much about the dialog plugin that you're using, it's hard to say why the subsequent dialogs are not showing up. Regardless, though, creating _modal dynamically should make it work. Another note: using onClick inside DOM elements is considered bad practice.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.