/    Sign up×
Community /Pin to ProfileBookmark

Why this functions stop working when I load the script into a div?

I’m using the “plyr.js” player and all works perfectly when I open the page separately, but when I load that page inside a div of another (i.e. when I load video.html inside a div of my index.html), the functions stops working…

Any ideas?

The code is the following…

<link rel=’stylesheet’ href=’https://cdn.plyr.io/3.4.6/plyr.css‘>

<video class=”video-fluid” id=”player” poster=”fotos/demo1.jpg” playsinline autoplay loop>
<source src=”demo1.mp4″ type=”video/mp4″>
</video>

<button type=”button” class=”btn js-stop” id=”stop”>Stop</button>

<script src=’https://cdn.plyr.io/3.4.6/plyr.js’></script>
<script>
document.addEventListener(‘DOMContentLoaded’, () => {

controls = [];
player = new Plyr(‘#player’, { controls });
window.player = player;
});
$(“#stop”).click(function(){
player.stop();
});
</script>

Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJan 22.2019 — when I load video.html inside a div of my index.html[/quote]How do you do this? By Ajax, by PHP include ...?
Copy linkTweet thisAlerts:
@rootJan 22.2019 — why are people now truing to populate a DIV with a HTML file??? That is what an IFRAME is for...

IF you are going to use an audio player, at the least, take advantage of the browsers native player, only add in a player if a format is not supported by it or the browser is a oddball and not fully supporting HTML5

&lt;link rel='stylesheet' href='https://cdn.plyr.io/3.4.6/plyr.css'&gt; would be much better on your own website, so put it on your site and you reduce any cross domain issues.
×

Success!

Help @lean3015 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...