views:

2541

answers:

1

I've been trying to get modal windows working on a new site for some time now. I first tried jqmodal and had no issues displaying the modals, but the close buttons never worked - or at least they worked on some pages but not on others. I put a great deal of effort into debugging and couldn't find the issue.

I recently tried out greybox to see if I had better luck, but ran into a very similar issue. The close button at the top-right works fine, but I can't make a button within the modal that acts as a close. I've tried:

onclick="parent.parent.GB_hide();"

and similar variants but they just load whatever href is set to within the modal. However, if I do:

onclick="top.window.location.href='www.google.com'; parent.parent.GB_hide();"

this will close the modal and open Google, as intended. What I can't figure out is why I can't make a button that will just plain close it.

I feel like I'm missing something pretty fundamental since I keep running into similar issues. Incidentally the site is written in ASP.NET MVC with jquery and I'm primarily testing on Firefox right now.

I also realize this question is a bit vague, so I appreciate any thoughts and can supply more info if requested. Thanks in advance!

Edit: I still have no idea how to proceed. Nick's ideas were well taken but I see no Javascript errors on the page with either Firebug or Venkman. As far as I can tell the window should be closing.

Why would the second 'onclick' event above work, but not the second?

+3  A: 

If I read your issue right, you simply are having problems closing the modal dialog.

I just put together an example using jqModal:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/tmp/jqModal.js" type="text/javascript"></script>
<style type="text/css">
    .jqmWindow
    {
        display: none;
        position: fixed;
        top: 17%;
        left: 50%;
        margin-left: -300px;
        width: 600px;
        background-color: #EEE;
        color: #333;
        border: 1px solid black;
        padding: 12px;
    }
    .jqmOverlay
    {
        background-color: #000;
    }
 .jqmWindow
    {
        position: absolute;

    }
</style>
<script type="text/javascript">
    $().ready(function() {
        $('#dialog').jqm();

        $('#jqmOpen').click(function() {
            $('#dialog').jqmShow();
            return false;
        });
    });
</script>
</head>
<body>
<a href="#" id="jqmOpen" name="jqmOpen">Open</a>
<div class="jqmWindow" id="dialog">
    <a href="#" class="jqmClose">Close</a>
    <input type="button" class="jqmClose" value="Close" id="jqmCloseBtn" name="jqmCloseBtn" />
    Some text in the modal dialog
   </div>
</body>
</html>

I have put both a hyperlink and a button just for example. It appears that jqModal needs/looks for the class to attach the close trigger.

EDIT:

I just tried your exact code from above and I didn't get a JavaScript error but also nothing happened, which is to be expected as my code does not know what GB_hide() is. So this got me thinking.

Is the button your clicking on like:

<input type="button" value="Close" id="Button1" name="Button1" onclick="parent.parent.GB_hide();" />

If so what is parent.parent.GB_hide()? Could GB_hide() be a function your are not implementing on this page.

Firebug shows me that parent.parent is the Window, so after putting:

<script type="text/javascript">
    function GB_hide() {
        alert('Close');
    }
</script>

on the page I now get an alert displayed.

Nick Clarke
Thanks, Nick. I understand how it works and have it working in some cases. I'm trying to figure out why the modal on one page closes as expected, but the one on another pages refuses to do so.
Most times I have had issues like this it has been caused by some unrelated JavaScript error. Do you have an example you can post/host?
Nick Clarke
Not right now. My JavaScript debugging skills are pretty slim, so if you could suggest a particular place to look or way to debug that might prove helpful. Thanks!
By far the best debugging tool is http://getfirebug.com, there is both a full Firefox plugin and a light version for other browsers. Firebug also has lots of plugins inself.
Nick Clarke
I mean Lite version not light :)
Nick Clarke
One of the first things you should do is check page validity and then check for javascript errors. Both can be done in FF from the web developer toolbar.
James S