I have a piece of JS which more or less looks like this
<script type="text/javascript" src="http://player.script.com/jsapi">
player = new playrer.Player('Yplayer',{
styleid: '0',
client_id: 'YOUR YOUKUOPENAPI CLIENT_ID',
vid: 'Replace the Youku Video ID'
});
</script>
Which would work if I directly drop it into my html document via script tag. But I am trying to call this by including a separate global javascript file. Can I avoid including the remote .jsapi via the <script>
3 Answers 3
a solution will be using jquery getScript() function
$.getScript( "http://player.script.com/jsapi", function( data, textStatus, jqxhr ) {
player = new playrer.Player('Yplayer',{
styleid: '0',
client_id: 'YOUR YOUKUOPENAPI CLIENT_ID',
vid: 'Replace the Youku Video ID'
});
});
Comments
You shouldn't use both the src attribute and javascript code (body content) inside the same tag.
Comments
As others have commented, the "jsapi" script will execute, but ignore your local javaScript. You need:
<script type="text/javascript" src="http://player.script.com/jsapi"></script>
<script type="text/javascript">
player = new playrer.Player('Yplayer',{
styleid: '0',
client_id: 'YOUR YOUKUOPENAPI CLIENT_ID',
vid: 'Replace the Youku Video ID'
});
</script>
You can put the embedded script in another file if you wish
src=attribute AND a script body..