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播放器在内容顶部的底部添加了一行代码,但找不到该行是什么。
Here is the code
$(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');
});
});
For some reason it will load everything but will not load the jw video player. However if I ask it to load the entire page rather than just '#content_inload' it will load the video even though that page has no head section, no scripts and is no more than the content inside '#content_inload'. I can only assume that the JW player adds a line of code to the bottom of the top of the content, but cannot find what that line is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您看到关于
.load()
方法的 jquery 源代码,他们会这样做。如果提供了选择器(如您的情况),他们会删除脚本以避免 IE 中出现“权限被拒绝”错误。
您需要使用 jquery
.get()
>类似的
另请注意,当您将
#content_inload
插入自身时,我已使用#inload_container
作为目标元素,实际上是重复的..更新
在您发表评论后,我尝试了以下有效的方法
似乎在内存中的 jquery 对象中创建脚本元素时可能会出现问题? (无法确定原因)
在您的具体情况下,上述解决方案可以工作,但它不是很优雅,因为它会将 ajax 调用返回的所有内容添加到 DOM 中,然后过滤掉我们不想要的内容。
最好只更改您的实际视频页面(从 ajax 加载的)并执行正常的
.load()
没有过滤掉任何东西..If you see the source code of jquery about the
.load()
method they doSo if a selector is provided (as is in your case) they remove the script to avoid Permission Denied errors in IE.
You will need to imitate this code using the jquery
.get()
methodsomething like
Also note that i have used the
#inload_container
as the target element as you were inserting the#content_inload
into itself, in effect duplicating ..Update
Well after your comment i tried the following that worked
Seems that there might be an issue when you create script elements in in-memory jquery objects ? (cant be sure of the reason)
In your specific case the above solution will work, but it is not very elegant, in the sense that it adds to the DOM everything returned from the ajax call and it then filters out the stuff we do not want..
It might be better altogether to just alter your actual video page (the one loaded from ajax) and do a normal
.load()
without filtering anything out..