1

このコードをフッターに追加しphpます。HTML ドキュメントで同じ構文を使用すると、すべてがうまく機能します。

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

改行に何か問題がありますか?

このようなコードを書くと、うまくいきます:

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

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

</script>

ご協力ありがとうござい
ます

4

1 に答える 1

4

</script>この時点で解析が終了するため、文字列に書き込むことはできません。
エスケープするだけです:

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

(他の時と同じように...)

于 2012-10-19T14:51:29.717 に答える