阻止来自 iframe/嵌入的弹出窗口

时间:2021-02-04 13:36:26

标签: javascript html iframe alert system-alert-window

我有很多 iframe,它们来自 Spotify,我不断收到弹出窗口,询问设备的内容,这将导致一个嵌入/iframe 在另一个停止时暂停。如何让所有 iframe 不允许弹出窗口?这只是我所拥有的一小部分:

我的网站可以在这里找到:https://50izac02.github.io/sb/music.html

<script>
        var songs1 = [
    "https://open.spotify.com/embed/track/1K9QXJtypYRMVrfHixmHh3",
 "https://open.spotify.com/embed/track/7clyJIrLkEbXUDwj1tC9zz", 
 "https://open.spotify.com/embed/track/0AB5CTb04eqXnV9hEZx9FL",
  "https://open.spotify.com/embed/track/31G6jTLEpHwGs3vpQ7iUJM"];
document.getElementById("spot1").src = songs1[Math.floor(Math.random() * 4) + 0];

var songs2 = [
"https://open.spotify.com/embed/track/1BlqKx3JtMKY3K6F0uUbqW",
"https://open.spotify.com/embed/track/7h2yzh9vIBxSBN3885QyQt",
"https://open.spotify.com/embed/track/4EAV2cKiqKP5UPZmY6dejk",
"https://open.spotify.com/embed/track/5dqrgmHHBuUzwYKBXJuIm0"
];
document.getElementById("spot2").src = songs2[Math.floor(Math.random() * 4) + 0];
    
    var songs3 = [
"https://open.spotify.com/embed/track/5dqrgmHHBuUzwYKBXJuIm0",
"https://open.spotify.com/embed/track/6QyBWey7P8ILuhS5RO7xYe",
"https://open.spotify.com/embed/track/5qrSlOut2rNAWv3ubArkNy",
"https://open.spotify.com/embed/track/0TN3FKCgNsck8Z0t463bU0",
    ];
    document.getElementById("spot3").src = songs3[Math.floor(Math.random() * 4) + 0];
    
    var songs4 = [
        "https://open.spotify.com/embed/track/5IcpFfoUZLU3G7b8BtppFi",
"https://open.spotify.com/embed/track/4R8RG1OWtp0ahfyGUcD76M",
"https://open.spotify.com/embed/track/6IHWepcSxwLdzM38nQSrnC",
"https://open.spotify.com/embed/track/6JyuJFedEvPmdWQW0PkbGJ",];
 document.getElementById("spot4").src = songs4[Math.floor(Math.random() * 4) + 0];

var songs5 = [
 "https://open.spotify.com/embed/track/41n0s0MdHk3SQYrJ4djpXb",
"https://open.spotify.com/embed/track/3uKxSYyWgMqu9LrgC2Lo7v",
"https://open.spotify.com/embed/track/0e9yz3Fz7Nn6I5E4XBP8no",
"https://open.spotify.com/embed/track/4hPpVbbakQNv8YTHYaOJP4",
];
document.getElementById("spot5").src = songs5[Math.floor(Math.random() * 4) + 0];
<div id="row 1">
        <iframe id="spot1" src="" width="250" height="90" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
        <iframe id="spot2" src="" width="250" height="90" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
        <iframe id="spot3" src="" width="250" height="90" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
        <iframe id="spot4" src="" width="250" height="90" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
        <iframe id="spot5" src="" width="250" height="90" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>
    </div>

1 个答案:

答案 0 :(得分:0)

您可以使用以下命令对 iframe 进行沙箱处理:sandbox="allow-scripts"。这应该会阻止他们产生弹出窗口。

相关问题