JavaScript - Añadir atributo sandbox a iframes

 
Vista:
sin imagen de perfil

Añadir atributo sandbox a iframes

Publicado por José Luis (1 intervención) el 25/08/2016 20:11:55
Hola a todos, veréis tengo una web estilo videotube con unos 1700 posts que contienen videos embebidos a través de un iframe, tal que así:

1
2
<iframe src="https://openload.co/embed/----.mp4" scrolling="no" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"
frameborder="0" height="100%" width="100%"></iframe>

Y necesito añadir automáticamente este atributo
1
sandbox="allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation"

Para que quede así:

1
2
<iframe src="https://openload.co/embed/----.mp4" scrolling="no" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"
frameborder="0" height="100%" width="100%" sandbox="allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation"></iframe>


He probado con los siguientes códigos, pero cuando inspecciono el código fuente en el navegador no incluyen el atributo :(

1
2
3
4
5
<script type="text/javascript">
$(document).ready(function() {
    $('iframe').attr('sandbox',allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation);
})
</script>

1
2
3
4
5
<script type="text/javascript">
$('iframe').attr({
  sandbox: 'allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation'
});
</script>

1
2
3
4
5
6
7
<script type="text/javascript">
$(document).ready(function() {
$('iframe').attr({
  sandbox: 'allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation'
});
})
</script>

1
2
3
4
5
<script type="text/javascript">
window.onload = function(){
       iframe.sandbox = 'allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation';
}
</script>

Gracias!
Un saludo :)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Añadir atributo sandbox a iframes

Publicado por xve (2100 intervenciones) el 25/08/2016 21:12:18
Prueba a ponerlo entre comillas... algo así:
1
$('iframe').attr('sandbox',"allow-forms allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation");

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar