开发者

jquery: update <script> src, update html created by script

开发者 https://www.devze.com 2023-02-17 01:10 出处:网络
This is a strange question, I think... I am embedding a video player using a <script> plugin (from \"bitsontherun\"). When the page loads, a video is displayed based on the url of the script\'s

This is a strange question, I think...

I am embedding a video player using a <script> plugin (from "bitsontherun"). When the page loads, a video is displayed based on the url of the script's src:

<script type="text/javascript" src="http://content.bitsontherun.com/players/123ABC-DEF456.js"></script>

where "123ABC-DEF456" is the unique id for the video. I would like to be able to reload the script with a new video id, and the player that it creates when a link is clicked.

Does a开发者_Go百科nyone have any insight on how to do this. I feel like I should be able to manipulate the DOM, but am unsure what function to use (getScript()?).


edit

I have decided to go another route, using an iframe and updating the src of the iframe with the video id in the query string.


I would just replace it with a brand new script tag. First I would put it in a containing div or span.

<div id="videobox">
<script type="text/javascript" src="http://content.bitsontherun.com/players/123ABC-DEF456.js"></script>
</div>

Then when you are ready to replace it, just replace the HTML content of #videobox.

var videoID; // set this however you want    
$("#videobox").html('<script type="text/javascript" src="http://content.bitsontherun.com/players/' + videoID + '.js"></script>');


I have decided to go another route, using an iframe and using jQuery to update the src of the iframe with the video id in the query string.

$(".botrtn").click(function(){
    var videoID = $(this).attr("id");  
    $('#frameplayer').attr('src', "video-frame.php?id="+videoID);   
    return false;
});


Was just doing some research and saw something that reminded me of your question here. Check out #3 on this page, the jQuery getScript() function. I think this would do what you want.

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

0

精彩评论

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