2012-05-26 66 views
0

有沒有一種方法可以在php中的<body>標記之前將腳本注入頁面?我已經看到了一些關於如何使用jquery實現的例子,但是jquery導致部分網站無法正常工作,因此我需要一個php代碼,這樣我才能在頁面的開始標記之前選擇性地插入腳本。在<body>之前包含腳本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,這樣我就可以包括在我需要的腳本我的模板文件的代碼,同時避免全球包容性被調用。

任何人都可以幫忙嗎?

最好, 邁克

+0

您是否在使用模板管理器?像http://www.smarty.net/一樣,或者你只是包括一個template.php文件,其中包含您的網站的HTML模板? – tftd

+0

我使用社交引擎,它是zend框架的擴展。該站點使用.tpl文件,其中標題包含在全局文件中。 –

回答

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

不,不幸的是,我有一個音樂播放器停止工作,當我把這個全球範圍內。 –

+2

然後你應該修復音樂播放器...... –

+0

那麼**你想做什麼**,把它放在''之前,而不是''之內?不,這是不可能的... – Jeroen

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

我有使用php和模板文件動態生成的頁面。只需將代碼添加到我的模板文件意味着將有2個主體標籤...這是我的困境。謝謝你的回答收音機。 –

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> 

我很感謝大家的時間,我不知道我是如何忽略了衝突。

best,

相關問題