0

I came accross some embeded javascript, e.g.

<script src="http://player.ooyala.com/player.js?embedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym&deepLinkEmbedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym"></script>

I would like to know how I can execute this dynamically. The reason is, I would like to be able to save the code in a DB and then execute it on the fly later.

I've already tried using $.get with the url and doing an eval on the response with no luck.

I use jQuery if this helps with a solution.

How could I go about this? Thanks.

1
  • You should add an ooyala tag.
    – jlaceda
    Apr 19, 2012 at 0:03

4 Answers 4

2

You're looking for $.getScript("http://player.ooyala.com/player.js?embedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym&deepLinkEmbedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym").

Note that if the script uses document.write, this is impossible.

2
  • Thanks, this looks about right. It works, only trouble is I'm tring to get it to appear in a particular div. It appears at the bootom of my webpage. I've tried the following: $('#qwerty').append($.getScript("http... but it still appears at the bottom of my page. What am I missing?
    – HGPB
    Apr 18, 2012 at 23:24
  • @Haraldo: You need to check the script's documentation to find out how to configure it.
    – SLaks
    Apr 19, 2012 at 3:00
1

You can append the entire string to the body using jquery

EDIT: have to escape some characters

$("body").append('\<script src="http://player.ooyala.com/player.js?embedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym&deepLinkEmbedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym"\>\<\/script\>');​
1
  • I just get an unterminated string literal using this. The issue starts at the first <script tag.
    – HGPB
    Apr 18, 2012 at 23:29
1

You can use: $.getScript("http://player.ooyala.com/player.js?embedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym&deepLinkEmbedCode=5oZDBoMzreLfI78xe1sCSLDmQQFyhXym&playerContainerId=myplayer")

Note the playerContainerId=myplayer part.

Ooyala has a playerContainerId parameter if you want to add the player as innerHtml of a div and not a document.write().

http://support.ooyala.com/developers/documentation/api/player_examples_qpass.html

0
0

You could request it if it supported CORS and then use jQuery's $.globalEval() to evaluate the response - it is executed (from memory) within a script element.

Alternatively, remove the script element on load and then inject it when you want to use it again.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.