0

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
  • 2
    You can't have both an src= attribute AND a script body.. Commented Jul 29, 2015 at 16:19
  • what's he trying to do is just including a file js which contains the script body. Commented Jul 29, 2015 at 16:20
  • John Resig: Degrading Script Tags Commented Jul 29, 2015 at 16:22

3 Answers 3

2

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'
 });
});
Sign up to request clarification or add additional context in comments.

Comments

1

You shouldn't use both the src attribute and javascript code (body content) inside the same tag.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.