2014-11-03 71 views
0

这适用于Firefox,但在Chrome上,我得到“Uncaught TypeError:无法读取属性'css'的空”错误on“onDialogOpen(){this.iframe.css({ ”模式窗口内的iFrame在Chrome上不工作

function show(options) { 


    // create our temporary iframe 
    this.iframe = $('<iframe name="' + (this.id = 'emh_' + +new Date) + '">') 
     .load($.proxy(onIframeLoad, this)); 

    // show our dialog 
    this.iframe.dialog($.extend(true, { 
     title: 'Entity Viewer', 
     modal: true, 
     draggable: false, 
     resizable: false, 
     width: 800, 
     height: 500, 
     buttons: { 
     'Save & Continue': $.proxy(submitIframeForm, this) 
     }, 
     open: $.proxy(onDialogOpen, this), 
     close: $.proxy(onDialogClose, this) 
    }, options)); 
    alert(options.path); 
    // since our dialog is showing now, let's update the src of the iframe 
    this.iframe.attr('src', options.path + '?modal=true&unique=' + this.id); 


    } 

function onDialogOpen() { 
    this.iframe 
     .css({ 
     width: '100%', 
     padding: 0, 
     border: 0, 
     margin: 0 
     }); 
} 

回答

0

不知道这是否会工作,但我有2种方法:

  1. 移动onDialogOpen你的表演方法内:

    function show(options) { 
    
    //your code 
    //... 
    //... 
    //this.iframe.attr('src', options.path + '?modal=true&unique=' + this.id); 
    
    //no need to pass this parameter since method has same this as parent one 
    
        function onDialogOpen() { 
         this.iframe 
          .css({ 
          width: '100%', 
          padding: 0, 
          border: 0, 
          margin: 0 
          }); 
        } 
    

    }

2. - 的IFrame负载之后创建此引用:

var _this = this; 
  • 修改此电话:

开:$。 proxy(function(){onDialogOpen(_this)},this)

更新onDialogOpen:

function onDialogOpen(_this) { 
    if (typeof _this != 'undefined') 
{ 
_this.iframe 
     .css({ 
     width: '100%', 
     padding: 0, 
     border: 0, 
     margin: 0 
     }); 
} 
else 
{ 
    this.iframe 
     .css({ 
     width: '100%', 
     padding: 0, 
     border: 0, 
     margin: 0 
     }); 
} 
} 
+0

SilentTremor感谢您的反馈,但不幸的是我仍然得到同样的错误 – 2014-11-04 09:42:27

+0

http://jsfiddle.net/pkxjmv9q/1/代码中的一些修正:对应该工作现在正确。 – SilentTremor 2014-11-04 13:28:41