简体   繁体   English

jQuery模式窗口在Internet Explorer中错误关闭

[英]jQuery modal window closes incorrectly in Internet Explorer

I'm having some problems regarding a jQuery modal window. 关于jQuery模式窗口,我遇到了一些问题。 I'm a dba and SQL programmer and my goal is to build up a query which dynamically builds an HTML which contains a flash which links to a modal window that has another flash in it. 我是dba和SQL程序员,我的目标是建立一个查询,该查询可动态构建一个HTML,其中包含一个Flash,该Flash链接到其中包含另一个Flash的模式窗口。 Well the query is done and works flawlessly. 好了,查询已经完成并且可以完美地工作了。 However, I tried it on Internet Explorer and (unlike firefox and chrome) when you want to close the modal window it closes the whole browser window (with a warning message that says "beware, the browser's trying to close this tab etc"). 但是,我在Internet Explorer上进行了尝试(并且与firefox和chrome不同),当您想关闭模式窗口时,它将关闭整个浏览器窗口(警告消息为“请注意,浏览器正在尝试关闭此选项卡,等等”)。

I used an already existing jquery modal window code and styling (I believe that both matter). 我使用了已经存在的jquery模态窗口代码和样式(我相信两者都很重要)。 The problem is, that the whole query is done and if I change the whole jquery modal window, I'll have to change the query's logic, and drastically (believe me, I've checked). 问题是,整个查询都已完成,如果我更改了整个jquery模态窗口,则必须彻底更改查询的逻辑(相信我,我已经检查了)。

So, my fastest solution would be to correct the jQuery code that is messing up the whole close thing (changing the sql stored proc would take a LOT of work). 因此,我最快的解决方案是纠正使整个事情弄糟的jQuery代码 (更改sql存储的proc会花费很多工作)。 This is because the original example I used as a reference had this problem (I just didn't notice, due to jQuery supposively being a cross-browser solution for everything). 这是因为我用作参考的原始示例存在此问题(我只是没有注意到,由于jQuery假定是所有内容的跨浏览器解决方案)。 You will see that it works flawlessly on FF and Chrome but not in IE Here's the link: http://www.mediafire.com/?mcz70n870qmjch9 您会发现它在FF和Chrome上可以完美运行,但在IE上却无法运行。这是链接: http : //www.mediafire.com/?mcz70n870qmjch9

Thanks a lot!!! 非常感谢!!!

Just in case I'm posting the code here as well: 以防万一我也在这里发布代码:

/// <reference path="jquery-1.3.2.min-vsdoc.js" />

/************************************************************************************************************
* SIMPLE MODAL v 2.0
* © 2009 FISHBOWL MEDIA LLC
* http://fishbowlmedia.com
***********************************************************************************************************/

(function ($) {

    /**********************************
    * CUSTOMIZE THE DEFAULT SETTINGS
    * Ex: 
    * var _settings = {
    *   id: 'modal',
    *   src: function(sender){
    *       return jQuery(sender).attr('href');
    *   },
    *   width: 800,
    *   height: 600
    * }
    **********************************/
    var _settings = {
        width: 800, // Use this value if not set in CSS or HTML
        height: 600, // Use this value if not set in CSS or HTML
        overlayOpacity: .85, // Use this value if not set in CSS or HTML
        id: 'modal',
        src: function (sender) {
            return jQuery(sender).attr('href');
        },
        fadeInSpeed: 0,
        fadeOutSpeed: 0
    }

    /**********************************
    * DO NOT CUSTOMIZE BELOW THIS LINE
    **********************************/
    $.modal = function (options) {
        return _modal(this, options);
    }
    $.modal.open = function () {
        _modal.open();
    }
    $.modal.close = function () {
        _modal.close();
    }
    $.fn.modal = function (options) {
        return _modal(this, options);
    }
    _modal = function (sender, params) {
        this.options = {
            parent: null,
            overlayOpacity: null,
            id: null,
            content: null,
            width: null,
            height: null,
            modalClassName: null,
            imageClassName: null,
            closeClassName: null,
            overlayClassName: null,
            src: null
        }
        this.options = $.extend({}, options, _defaults);
        this.options = $.extend({}, options, _settings);
        this.options = $.extend({}, options, params);
        this.close = function () {
            jQuery('.' + options.modalClassName + ', .' + options.overlayClassName).fadeOut(_settings.fadeOutSpeed, function () { jQuery(this).unbind().remove(); });
        }
        this.open = function () {
            if (typeof options.src == 'function') {
                options.src = options.src(sender)
            } else {
                options.src = options.src || _defaults.src(sender);
            }

            var fileExt = /^.+\.((jpg)|(gif)|(jpeg)|(png)|(jpg))$/i;
            var contentHTML = '';
            if (fileExt.test(options.src)) {
                contentHTML = '<div class="' + options.imageClassName + '"><img src="' + options.src + '"/></div>';

            } else {
                contentHTML = '<iframe width="' + options.width + '" height="' + options.height + '" frameborder="0" scrolling="no" allowtransparency="true" src="' + options.src + '">&lt/iframe>';
            }
            options.content = options.content || contentHTML;

            if (jQuery('.' + options.modalClassName).length && jQuery('.' + options.overlayClassName).length) {
                jQuery('.' + options.modalClassName).html(options.content);
            } else {
                $overlay = jQuery((_isIE6()) ? '<iframe src="BLOCKED SCRIPT\'&lt;html&gt;&lt;/html&gt;\';" scrolling="no" frameborder="0" class="' + options.overlayClassName + '"></iframe><div class="' + options.overlayClassName + '"></div>' : '<div class="' + options.overlayClassName + '"></div>');
                $overlay.hide().appendTo(options.parent);

                $modal = jQuery('<div id="' + options.id + '" class="' + options.modalClassName + '" style="width:' + options.width + 'px; height:' + options.height + 'px; margin-top:-' + (options.height / 2) + 'px; margin-left:-' + (options.width / 2) + 'px;">' + options.content + '</div>');
                $modal.hide().appendTo(options.parent);

                $close = jQuery('<a class="' + options.closeClassName + '"></a>');
                $close.appendTo($modal);

                var overlayOpacity = _getOpacity($overlay.not('iframe')) || options.overlayOpacity;
                $overlay.fadeTo(0, 0).show().not('iframe').fadeTo(_settings.fadeInSpeed, overlayOpacity);
                $modal.fadeIn(_settings.fadeInSpeed);

                $close.click(function () { jQuery.modal().close(); });
                $overlay.click(function () { jQuery.modal().close(); });
            }
        }
        return this;
    }
    _isIE6 = function () {
        if (document.all && document.getElementById) {
            if (document.compatMode && !window.XMLHttpRequest) {
                return true;
            }
        }
        return false;
    }
    _getOpacity = function (sender) {
        $sender = jQuery(sender);
        opacity = $sender.css('opacity');
        filter = $sender.css('filter');

        if (filter.indexOf("opacity=") >= 0) {
            return parseFloat(filter.match(/opacity=([^)]*)/)[1]) / 100;
        }
        else if (opacity != '') {
            return opacity;
        }
        return '';
    }
    _defaults = {
        parent: 'body',
        overlayOpacity: 85,
        id: 'modal',
        content: null,
        width: 800,
        height: 600,
        modalClassName: 'modal-window',
        imageClassName: 'modal-image',
        closeClassName: 'close-window',
        overlayClassName: 'modal-overlay',
        src: function (sender) {
            return jQuery(sender).attr('href');
        }
    }
})(jQuery);

And the style: 和样式:

.modal-overlay {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #131313;
    opacity: .85;
    filter: alpha(opacity=85);
    z-index: 101;
}
.modal-window {
    position: fixed;
    top: 50%;
    left: 50%;
    margin: 0;
    padding: 0;
    z-index: 102;
    background: #fff;
    border: solid 8px #000;
    -moz-border-radius: 8px;
    -webkit-border-radius: 8px;
}
.close-window {
    position: absolute;
    width: 47px;
    height: 47px;
    right: -23px;
    top: -23px;
    background: transparent url(../images/close-button.png) no-repeat scroll right top;
    text-indent: -99999px;
    overflow: hidden;
    cursor: pointer;
}

Thanks a ton in advance everyone =-) 提前谢谢大家=-)


EDIT : Daniele suggested that the problem might be on this line: 编辑 :Daniele建议问题可能在此行上:

jQuery('.' + options.modalClassName + ', .' + options.overlayClassName).fadeOut(_settings.fadeOutSpeed, function () { jQuery(this).unbind().remove(); });

I did what he suggested and the result was this: It still doesn't work at all on IE (meaning that it still asks to close the whole window and not just the modal), and correctly shows and closes a first modal in FF and chrome, but after closing the first one its not able to correctly show another one. 我做了他的建议,结果是:它在IE上仍然根本不起作用(这意味着它仍然要求关闭整个窗口,而不仅仅是模式),并正确地显示和关闭FF和chrome,但是关闭第一个后,它无法正确显示另一个。


Replace close() method of modal with closeModal or something similar: 用closeModal或类似的东西替换模式的close()方法:

$.modal.closeModal = function () {
    _modal.closeModal();
}

[...] [...]

this.closeModal = function () {
        jQuery('.' + options.modalClassName + ', .' + options.overlayClassName).fadeOut(_settings.fadeOutSpeed, function () { jQuery(this).unbind().remove(); });
    }

[...] [...]

$close.click(function () { jQuery.modal().closeModal(); });
            $overlay.click(function () { jQuery.modal().closeModal(); });

for me it works... 对我来说有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM