开发者

Jquery Load element page works with everything except videos

Here is the co开发者_StackOverflow中文版de

$(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.


If you see the source code of jquery about the .load() method they do

...
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 
);
...

So 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() method

something like

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

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

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

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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜