0

<body>PHPのタグの前にページにスクリプトを挿入する方法はありますか? jqueryでこれを行う方法の例をいくつか見ましたが、jqueryはサイトの一部を正しく機能させないため、ページの開始タグの前にスクリプトを選択的に挿入できるようにphpコードが必要です.

すなわち。

.....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="jquery.internads.js"></script>
<script>

    $(document).ready(function(){       

        // Call Intern Ads              
        $().tcInternAds({
            title: "Support Our Sponsors!",
            url: "adpage.html",
            timeout: 10,
            deplay: 0,
            wait: 0,
            closeable: true
        });

    });

</script>
<body>
<div class="xxxxx">
...............</div>

可能であればphpを使用できるようにしたいので、グローバルな包含を避けながらスクリプトを呼び出す必要があるテンプレートファイルにコードを含めることができます。

誰でもこれを手伝ってもらえますか?

最高、マイク

4

3 に答える 3

0

コンテンツをindex.php(またはそれが呼ばれるもの)に入れます。

次のようになります。

<?php

...phpcode...

?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="jquery.internads.js"></script>
<script>
...
</script>
<body>
<div class="xxxxx">

<?php

another php code

?>

</div>
于 2012-05-26T20:32:41.890 に答える
0

ヘッドコードを挿入または置換することなく、問題の解決策を見つけました。問題は、私のサイトに mootools が含まれており、jquery が競合していることです。使用する名前空間を定義する jQuery noConflict を使用して問題を解決したため、$ ではなくカスタム変数を使用して問題を解決しました。

これは、jquery/mootools の競合を回避するための私の実用的なソリューションです。

<link href="/internAds.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="/jquery.internads.js"></script>
<script>
var $j = jQuery.noConflict();
    $j(document).ready(function(){      

        // Call Intern Ads              
        $j().tcInternAds({
            title: "Support Our Sponsors!",
            url: "/adpage.html",
            timeout: 15,
            deplay: 0,
            wait: 5,
            closeable: false
        });

    });

</script>

みんなの時間に感謝します。どうやって紛争を見落としたのかわかりません。

一番、

于 2012-05-26T21:32:52.323 に答える
0

単純に<head>作品の中に入れてみませんか?

<head>
.....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="jquery.internads.js"></script>
<script>

    $(window).load()(function(){       

        // Call Intern Ads              
        $().tcInternAds({
            title: "Support Our Sponsors!",
            url: "adpage.html",
            timeout: 10,
            deplay: 0,
            wait: 0,
            closeable: true
        });

    });

</script>
</head>
<body>
<div class="xxxxx">
...............</div>
于 2012-05-26T20:28:06.213 に答える