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>

asked Jul 29, 2015 at 16:15
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'
 });
});
answered Jul 29, 2015 at 16:22
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.

Barett
5,9556 gold badges54 silver badges57 bronze badges
answered Jul 29, 2015 at 16:20

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

answered Jul 29, 2015 at 16:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.