最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - SyntaxError: Unexpected EOF - Stack Overflow

programmeradmin1浏览0评论

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') || ('patible')) { */

        // 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

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') || ('patible')) { */

        // 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

Share Improve this question asked Oct 19, 2012 at 14:48 ogniogni 3271 gold badge7 silver badges17 bronze badges 3
  • Sometimes invalid characters can work their way into code when you copy/paste code from websites. – NullPoiиteя Commented Oct 19, 2012 at 14:50
  • How/where/when do you call checkBrowserName() ? – Dr.Molle Commented Oct 19, 2012 at 14:53
  • I don't see any PHP in your code – Alvin Wong Commented Oct 19, 2012 at 14:56
Add a ment  | 

1 Answer 1

Reset to default 4

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...)

发布评论

评论列表(0)

  1. 暂无评论