【发布时间】:2016-07-03 16:24:49
【问题描述】:
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')
here、here和here的答案我都试过了,基本上所有可能的解决方案。
要指出的另一件有趣的事情是 window 仅在 Safari 上返回 undefined!
/**
* @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();
},
});
【问题讨论】:
-
你可能想使用
document.querySelector(".active iframe") -
我已经试过了:(
-
刚刚在 IE 中测试过,似乎可以正常工作。你能检查一下我刚刚发布的 plnkr 链接吗
-
请分享重现问题所需的代码。我们甚至不知道您是否有一个带有活动类或 iframe 的元素......顺便说一句,这与backbone.js 有什么关系?
-
@TJ 对不起,我迷路了。它在 Safari 和 IE 中不起作用。该元素存在是因为它可以在 Chrome+Firefox 中运行,不是吗?
标签: javascript iframe backbone.js safari