SyntaxError: Unexpected EOF

我的未来我决定 提交于 2019-12-24 06:53:29

问题


I add this code into my php footer: When I use the same syntax in an HTML document everything works well for me.

   <body>
    ...

        <script type="text/javascript">     

        // Browser detection
        function checkBrowserName(name){ 
        var agent = navigator.userAgent.toLowerCase();  
        if (agent.indexOf(name.toLowerCase())>-1) {  
        return true;  
        }  
        return false;  
        }  

        if(checkBrowserName('opera')){
        /* load nothing */
        }

        else if(checkBrowserName('')) {
        /* else if(checkBrowserName('firefox') || ('msie') || ('safari') || ('konqueror') || ('omniweb') || ('webtv') || ('icab') || ('compatible')) { */

        // Insert script
        document.write('<script src="assets/javascripts/hyphenate.min.js" type="text/javascript"></script>');
        document.write('<\/script>');

        // Script options
        document.write('<script type="text/javascript">');
        document.write('Hyphenator.config({');
        document.write('displaytogglebox : false,');
        document.write('minwordlength : 4');
        document.write('});');
        document.write('Hyphenator.run();');
        document.write('<\/script>');

        }
        </script>
    ...
    </body>

Is something wrong with my line-breaks?

When I write the code like this, it will work for me:

<script type="text/javascript" src="assets/javascripts/hyphenate.min.js"></script>
<script type="text/javascript">

Hyphenator.config({
    displaytogglebox : false,
    minwordlength : 4
});
Hyphenator.run();

</script>

Thanks for your help
Ogni


回答1:


You cannot write </script> into strings, because parsing ends at this point then.
Just escape it:

document.write('<script src="assets/javascripts/hyphenate.min.js" type="text/javascript"><\/script>');

(like you did the other times...)



来源:https://stackoverflow.com/questions/12976772/syntaxerror-unexpected-eof

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!