javascript button that allows changing the bootstrap meta tag

0

I need a button on my Drupal 7 site, where when I press it, I change the meta tag content

<meta name="viewport" content="width=device-width, initial-scale=1.0">

bootstrap located in sites/all/themes/bootstrap/templates/system/html.tpl.php , to

content="1024" 

and this button is only displayed on mobile.

Any suggestions?

    
asked by Geek 14.07.2017 в 18:04
source

1 answer

2

I do not know if this is more or less what you are looking for: I have made a button that changes the meta tag but by referencing it with an id, it changes both the text of the button and the meta attribute.

$(document).ready(function() {

  var textoAnterior = "Cambiar Content de la etiqueta meta a 1024";
  var textoNuevo = "Cambiar Content de la etiqueta meta al original";
  var valorAtributoNuevo = "1024";
  var valorAtributoAnterior = "width=device-width, initial-scale=1.0";

  $("#botonCambiarContent").on("click", function() {

    valorAtributoActual = $("#etiquetaACambiar").attr("content");

    if (valorAtributoActual !== valorAtributoNuevo) {
      $("#etiquetaACambiar").attr("content", valorAtributoNuevo);
      $("#botonCambiarContent").text(textoNuevo);
    } else {
      $("#etiquetaACambiar").attr("content", valorAtributoAnterior);
      $("#botonCambiarContent").text(textoAnterior);
    }

  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<meta id="etiquetaACambiar" name="viewport" content="width=device-width, initial-scale=1.0">

<button id="botonCambiarContent" type="button">Cambiar Content de la etiqueta meta a 1024</button>
    
answered by 30.08.2017 / 19:07
source