1

I need to dynamically add more items (videos. which is in script form) to div. In below code, append doesn't do anything. I have tried to append script in string form too (i.e. ""). I appreciate any help!!!!

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

  <div>
      <script type="text/javascript" src="http://video.foxnews.com/v/embed.js?id=1993203907001&w=466&h=263"></script>
  </div>

<script>
$(document).ready(function() {
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = 'http://video.foxnews.com/v/embed.js?id=1993203907001&w=466&h=263';
  $("div").append(script);
});
</script>

</body>
</html>
5
  • 1
    usually I always ad an id to a div like <div id="mydiv"> and then use $("mydiv").append(script) Commented Nov 27, 2012 at 23:52
  • @Terradon - it shouldn't make any difference. anyways I also do that In my code :) Commented Nov 28, 2012 at 0:05
  • It has to do with the way you're defining your var script. I would suggest attempting to append the html script tag as a string, and share your results here. Commented Nov 28, 2012 at 0:08
  • Is this your real script?? because you add the same video you already have in your div?? Commented Nov 28, 2012 at 0:09
  • ideally I pull down new video dynamically and add it. this is to keep it simple. Commented Nov 28, 2012 at 0:26

3 Answers 3

1

Unsafe JavaScript attempt to access frame with URL file:///C:/Users/###/Desktop/test.html from frame with URL http://video.foxnews.com/v/video-embed.html?video_id=1993203907001&w=466&h=263&loc=. Domains, protocols and ports must match.

Your trying to access something from a different domain => XSS

http://en.wikipedia.org/wiki/Cross-site_scripting

and also

https://support.ookla.com/entries/21097566-what-is-crossdomain-xml-and-why-do-i-need-it

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for respond. If you copy/paste my code in notepad and save as .html, you will see that it can embed video. but ideally it should have two videos.
1

jQuery handles <script /> tags in a special way (.append() -> .domManip())
Just use the DOM method .appendChild() instead

document.getElementsByTagName('div')[0].appendChild(script);​

Read this answer for a deeper look into the why?

Comments

-1

Try replacing this line

$("div").append(script);

with this

document.getElementsByTagName('div')[0].appendChild(script);​

Check Fiddle

The native .appendChild method seems to be working , but the jQuery .append() does not seem to be working for some reason..

4 Comments

@YuryTarabanko Why you think its irrelevant? It addresses the problem (just missing an explanation)
@Sushanth - It doesn't address the problem. are you able to see video in fiddle? it should embed video if it works.
I think that is another issue for which answer given by pensan might be in the right direction...
@Sushanth: It doesn't. jQuery handles scripts correctly. Check network tab just to make sure that script was actually loaded. Your solution adds nothing.

Your Answer

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.