jQuery + External javascript: How to embed videoplayer in div
I just started with jQuery and so far I have a really good impression of the framework. But now I have a problem that I can't figure out on myself. I want to embed an external javascript file that loads a videoplayer and displays it. If I include the <script>...</script>
directly in HTML it loads just fine. But when I try to load it with jQuery it has very different behaviors in several browsers but it doesn't work in a single one. Either the player is not loaded at all or it doesn't update the selected div but reloads the player on a blank page. This is the source:
<html>
<head>
<style type="text/css">
div#test {
width: 100%;
height: 500px;
margin: 10px auto;
padding: 5px;
border: 1px solid #777;
background-color: #fbca93;
text-align: center;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var video = "<script type=\'text\/javascript\' src=\'http:\/\/www.physicalfitnet.com\/video_syndication\/embed\/jssingle.aspx?vid=651&pub=9DF8233261D101B86368400385B8FF2E\'><\/script>";
$("div#test").html(video);
});
</script>
</head>
<body>
<div id="test"> Hi</div>
</body>
<开发者_运维百科/html>
I uploaded everything to http://kernast.de/test ... any help is appreciated. THX
I couldn't get at the script (got an ASP NullReferenceException trying to download the script), but is it using document.write
to write to the page? Because if so, those scripts must be included during the parsing stage, they can't be added afterward. This is because they actually emit HTML to the document for the parser to work with. Calling document.write
after the document has been parsed doesn't do anything.
精彩评论