简体   繁体   中英

Audio file plays automatically when going back to the previous page

I have audio/videos that you can play in a portfolio area on my website. If I play one of them, and then go the previous page, and then back to my page using next button of my browser, the audio will play automatically even though I didn't click on anything. The exact same behaviour will occur if I play a video or audio, click to visit another page, and then click on the previous page button of my browser.

How could I prevent that?

Here's some code :

<iframe class="ms-slide-video" src="about:blank" allowfullscreen="true" style="width: 100%; height: 100%; display: none;"></iframe>

Gets transformed to :

<iframe class="ms-slide-video" src="/dacontent/video/mp4/2205.mp4?&amp;autoplay=1" allowfullscreen="true" style="width: 100%; height: 100%; display: block; opacity: 1;"></iframe>

When I click on play.

But when the bug occurs, the iframe's src stays "about:blank".

Here's the iframe content at all time :

<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
<video controls="" autoplay="" name="media">
<source src="http://www.kang.fr/dacontent/video/mp4/2205.mp4?&amp;autoplay=1" type="video/mp4"></video>
</body>
</html>

I found and tried removing "&autoplay=1" in the src attribute of source, with no success. Couldn't find out how to change video's autoplay attribute though.

I have resolved my issue.

First, as I said :

But when the bug occurs, the iframe's src stays "about:blank".

This was wrong . My browser inspector was blatantly lying to me about those iframes. Actually, the src attribute was filled with the video link.

So I had to empty the attribute of those iframes, but only when the page was fully loaded. Before that, it wouldn't be any use because the iframes were not generated yet.

Here's the final code (it is specific to Masterslider's slides, but will work for any iframe that causes this problem).

jQuery(window).load(function ($) {
    if (jQuery('iframe.ms-slide-video').length) {
        jQuery('iframe.ms-slide-video').attr('src', '');
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM