简体   繁体   English

ASP.Net回发中断jQuery FancyBox

[英]ASP.Net Post-back Breaks jQuery FancyBox

I have a FancyBox help link, on an ASP.Net aspx page, that is registered as such: 我在ASP.Net aspx页面上有一个FancyBox帮助链接,其注册如下:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.js"></script>
    <link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.3.4.css" media="screen" />

    <script type="text/javascript">
        $(document).ready(function() {

        $("#help").fancybox({
            'width': '90%',
            'height': '90%',
            'autoScale': true,
            'transitionIn': 'elastic',
            'transitionOut': 'none',
            'titleShow': false,
            'type': 'iframe'
        });

    });
  </script>

It works fine, but after 2 post backs (still works after 1) an exeption is thrown here (in fancybox.js) saying 'wrap' is not an object, when I click the help link: 它工作正常,但是在2次回发后(仍然在1次后仍然有效),当我单击帮助链接时,在此处(在fancybox.js中)抛出了一个异常,说'wrap'不是一个对象:

    $.fancybox.center = function() {
    var view, align;

    if (busy) {
        return; 
    }

    align = arguments[0] === true ? 1 : 0;
    view = _get_viewport();

    if (!align && (wrap.width() > view[0] || wrap.height() > view[1])) {
        return; 
    }

After the third post back, an error is thrown before the page is completely loaded within the jquery.js file Microsoft JScript runtime error: Object doesn't support this property or method pointing no where in peticular. 第三回发后,在页面完全加载到jquery.js文件中之前,将引发错误Microsoft JScript runtime error: Object doesn't support this property or method ,在Peticular中不指向任何位置。

Any ideas why post backs would be breaking fancybox? 有什么想法为什么回发会破坏fancybox吗?

The solution is add "lazy_loader". 解决方法是添加“ lazy_loader”。

This will load your fancybox classes in each postback 这将在每个回发中加载您的fancybox类

<script type="text/javascript">
    $(document).ready(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(lazy_loader);
        lazy_loader();
    });

    function lazy_loader() {
        $("#help").fancybox({
            'width': '90%',
            'height': '90%',
            'autoScale': true,
            'transitionIn': 'elastic',
            'transitionOut': 'none',
            'titleShow': false,
            'type': 'iframe'
        });
    }
</script>

This should work just fine 这应该很好

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

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