Can I write a [removed] tag inside a [removed] tag

后端 未结 2 1116
甜味超标
甜味超标 2020-12-19 17:37

This is my code. I\'m trying to stop running an external js file when screen width is less than 1025.



        
相关标签:
2条回答
  • 2020-12-19 18:05
    <script type="text/x-jQuery-tmpl">
        var gdsize = 1025;          
        if(window.innerWidth>=gdsize) {
    
        <script type="text/javascript">
            <!-- Some javascript here -->
            window.cookieconsent_options = {"message":"\"Geek Dashboard uses cookies to make sure you get the best experience on our website.\" -","dismiss":"It's OK","learnMore":"More Details Here","link":"http://www.geekdashboard.com/cookies/","theme":"dark-bottom"};
            }
        {{html "</sc"+"ript>"}}
    </script>
    

    You can use {{html "</sc"+"ript>"}} in place of </script>

    Explanation [update]:

    When you use a </script> HTML tag inside a quoted (literal) string, the tag is treated as a closing tag rather than as a portion of the string. So you cannot directly use the </script> tag inside a script section.

    One work-around is to escape the </script> tags and/or split up the <script> tags:

    var scriptEnd = "</scr" + "ipt>";
    document.write(scriptEnd);
    
    0 讨论(0)
  • 2020-12-19 18:09

    Why would you use a nested script to modify an object property?

    It can be solved in a much simpler way since you're already "in the script":

    <script type="text/javascript">
      var gdsize = 1025;          
      if(window.innerWidth>=gdsize) {
    
        window.cookieconsent_options = {"message":"\"Geek Dashboard uses cookies to make sure you get the best experience on our website.\" -","dismiss":"It's OK","learnMore":"More Details Here","link":"http://www.geekdashboard.com/cookies/","theme":"dark-bottom"};
    
      }    
    </script>
    
    0 讨论(0)
提交回复
热议问题