1

I have a system loading in a youtube video using an object tag with the id="cstmVideoContent" and the data=(youtube link). I need to extract the content in the object's data property using javascript/jquery and render it elsewhere on the page.

Here's my relevant html:

<object id="cstmVideoContent" width="400" height="320" type="application/x-shockwave-flash" data="NEED THE VIDEO LINK THAT IS HERE" style="visibility: visible;"></object>

Based on my admittedly crude knowledge of javascript/jquery, it seems like this should work:

var videolink = $('object#cstmVideoContent').attr('data');

But it is coming back as "undefined" every time. Is this method possible, am I doing something wrong, or is there a better way? Thanks!


Document ready can not be used with jQuery Mobile because of how jQuery Mobile handles page loading.

To find more about page events, its difference to document ready take a look at this ARTICLE or find it HERE.

Working jsFiddle example: http://jsfiddle.net/Gajotres/CPpBD/

Basically all you have to do is change this:

$(document).ready(function () {
    $('.flexslider').flexslider({
        animation: "slide",
        animationLoop: false,
        itemWidth: 80,
        itemMargin: 5
    });
});

to this:

$(document).on('pageshow', '#index', function(){       
    $('.flexslider').flexslider({
        animation: "slide",
        animationLoop: false
    });
});

You can read more about pageshow event in a link I posted at the begging of this answer.

4

1 に答える 1

3

これは私がデータに対して行うことです:

<object id="cstmVideoContent" width="400" height="320" type="application/x-shockwave-flash" data-link="NEED THE VIDEO LINK THAT IS HERE" style="visibility: visible;"></object>

var personalvideo = $('#cstmVideoContent').data('link');

これはHTML5に基づいているため、互換性についていくつかのブラウザーでテストすることを検討する必要があります。

参照:http ://api.jquery.com/data/

于 2013-03-14T16:18:56.867 に答える