2010-11-07 45 views
1

下面是代码jQuery的负载元件页作品的一切,除了视频

$(function() { 
    if(location.hash) $("#content_inload").load(location.hash.substring(1) + ' #content_inload'); 
    $("#nav a").click(function() { 
     $("#content_inload").load(this.hash.substring(1) + ' #content_inload'); 
    }); 
}); 

出于某种原因,它会加载的一切,但不会加载JW视频播放器。但是,如果我要求它加载整个页面而不是'#content_inload',它将加载视频,即使该页面没有头部,没有脚本,也不会超过'#content_inload'内的内容。我只能假设JW播放器将一行代码添加到内容顶部的底部,但无法找到该行的内容。

+0

在样品http://www.divethegap.com/update/community/videos/(点击测试视频)。 – 2010-11-07 14:49:13

+0

加载页面中的内容是什么? – 2010-11-07 14:50:25

+0

\t \t \t \t \t \t
(没有其他)如果我告诉它加载整个页面而不是只是'#content_inload',但'#content_inload'是整个页面,所有的工作都很好。只是一个样本来测试这个问题,这不是最终结果将如何。 – 2010-11-07 15:00:46

回答

1

如果你看到的jQuery的有关​​方法的源代码,他们做

... 
self.html( 
    selector ? 
    // Create a dummy div to hold the results 
    jQuery("<div>") 
     // inject the contents of the document in, removing the scripts 
     // to avoid any 'Permission Denied' errors in IE 
     .append(res.responseText.replace(rscript, "")) 

     // Locate the specified elements 
     .find(selector) : 

    // If not, just inject the full result 
    res.responseText 
); 
... 

所以,如果提供一个选择(如你的情况),他们删除脚本,以避免在IE权限被拒绝的错误。

你需要使用jQuery .get()方法

$("#nav a").click(function() { 
    $.get(this.hash.substring(1), function(response){ 
     var dummy = $('<div>').append(response).find('#content_inload'); 
     $("#inload_container").html(dummy); 
    }); 
}); 

另外请注意,我已经使用了#inload_container作为目标元素为你插入#content_inload到自身模仿这个代码,实际上是复制的。


更新

您的评论后,那么我想,工作

$("#nav a").click(function() { 
    $.get(this.hash.substring(1), function(response){ 
     $("#inload_container").empty().append(response).find('>*:not(#content_inload)').remove(); 
    }); 
}); 

下面似乎有可能是当你创建在内存中的jQuery对象的脚本元素的问题吗? (不能确定的原因

在你的具体情况,上述解决方案将工作,但它不是很优雅,从它意味着它添加到DOM从ajax调用返回的一切,然后过滤出来的东西,我们不希望..

它可能会更好干脆就只是改变你的实际视频页面(一个从阿贾克斯加载),做一个正常的​​没有任何过滤了..

+0

谢谢你告诉我关于IE的问题。已经实现了您的代码,但仍然无法加载视频。视频仅在脚本未定义要加载的元素时加载。 – 2010-11-07 16:06:40

+0

@Robin,增加了一个替代品加上一些评论.. – 2010-11-07 16:21:41

+0

感谢您的帮助 – 2010-11-07 16:32:08