Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Loading Single-Line Embed Script after DOM/Page is done loading

Good afternoon,

I am currently a jwplayer user with commercial license and I am trying to build up a web app using dynamic JWPlayer Single-Line Embed.

Ex: <script src="//"> </script>

Based on the video is selected, different MEDIAID is feeding to the html page. However, I have tried variety method, including create a script placeholder on my html but it doesn't seem to work. I am always getting this error for some reasons and I couldnt be able to work around.

The error that I get is
"Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened."

"uncaught typeerror jwplayer(...).setup is not a function"

This is what I have so far for testing purpose:


<body ng-app="myApp" ng-controller="HomeCtr">
<div class="moreTest">
<script ng-src="//{{player}}"></script>

app.controller('HomeCtr', function ($scope) {
console.log("I am in HomeCtr ");
$scope.player = "AAAAAA-BBBBBB.js?sig=CCCCCCCCCCCC&exp=DDDDDDD"


// var fileref = document.createElement('script');
// fileref.setAttribute("type", "text/javascript");
// fileref.setAttribute("src", "//;
// alert(fileref);
// document.getElementsByTagName("head")[0].appendChild(fileref);

Add to my question:

If I am placing the embedded scripts directly into html, it works fine. But I want to inject different MEDIAID based on user's selection.

I would prefer a single line embedded script rather than to create an instance of jwplayer.

Thank you for your time


1 Community Answers


JW Player Support Agent  
0 rated :

Hello Long,

Based on your error
“Failed to execute ‘write’ on ‘Document’: It isn’t possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.”

You may want to change your approach. Perhaps you could just call jwplayer().setup() or jwplayer().load() when you click on a media id because that will load the new content into the previously instantiated jwplayer.

So first setup the player using your single line embed code, then call jwplayer().load() to load new content.

This question has received the maximum number of answers.