TypeError:undefined不是对象 - Safari& IE

时间:2016-03-17 10:59:00

标签: javascript iframe backbone.js safari

runAnimation: function(){
  var iframe = document.querySelector('.active iframe');
  window.frames[iframe.id].contentWindow.runAnimation();
},

以上代码在Safari中打印以下错误:

TypeError: undefined is not an object (evaluating 'window.frames[iframe.id].contentWindow.runAnimation')

我已经尝试了答案hereherehere,基本上是每个可能的解决方案。

另一个有趣的事情是窗口仅在Safari上返回未定义



/**
 * @property {array} Templates.slide - The template part for each slide
 * Html template for app
 */

//Iframe Template
presenter.Templates.slide = [
  '<iframe id="slide-<%= id %>" class="slide" data-disable-back="<%= disableBack %>" data-disable-forward="<%= disableForward %>" data-position="<%= position %>" data-src="<%= url %>">',
].join('\n');




/**
 * Default options for the carousel.
 * @public
 */

//Owl Carousel options
	Owl.Defaults = {
		...
		// Classes and Names
		themeClass: 'owl-theme',
		baseClass: 'owl-carousel',
		itemClass: 'owl-item',
		centerClass: 'center',
		activeClass: 'active'
	};

/**
 * The main view for the presentation
 * This renders a collection presentation
 * Builds owlCarousel and attaches api controls
 */
presenter.PresentationView = Backbone.View.extend({
  ...
  
  /**
   * Runs slide animation. Called on the slide itself once its loaded
   */
  runAnimation: function(){
    var iframe = document.querySelector('.active iframe');
    window.frames[iframe.id].contentWindow.runAnimation();
  },
  ...

/**
 * Adds listners for carousel events. Used to trigger runAnimation along with
 * other function
 */
  carouselEvents: function(){
    var self = this;
    this.slider.on('translated.owl.carousel', function(){
      self.showControls();
      self.runAnimation();
    });
  },
  
/**
 * Standard backbone method. Called when view is instantiated
 * @param {object} options - Options passed when creating the view
 *                           (such as instanceURL)
 */
  initialize : function(options){
    this.options = options;
    this.render();
    this.buildSlider();
    this.loadFour();
    this.carouselControls();
    this.carouselEvents();
    this.keyNavigation();
    this.UIEvent();
    this.reScale();
  },

});
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我尝试过这样似乎有效

var iframe = document.querySelector('.container iframe');
window.frames[iframe.id].contentWindow.runAnimation();

https://plnkr.co/edit/0pquvlK3beF1pqMcU1lc?p=preview