簡體   English   中英

將PHP代碼添加到Drupal頁面以添加Javascript

[英]Adding PHP code to Drupal Page for adding Javascript

我試圖將一些JavaScript添加到Drupal頁面中,以在沒有地址欄等的彈出窗口中打開鏈接。此后,我得知您不能僅將JS嵌入“完整HTML”視圖中。 (腳本標記使用HTML注釋注釋掉),因此我使用了PHP函數drupal_add_js()使用PHP進入模式,但是在呈現HTML時,PHP代碼使用HTML注釋注釋掉了。

<?php
$myscript = 'function openWindow(){
var browser=navigator.appName;
if (browser==”Microsoft Internet Explorer”)
{
window.opener=self;

}
window.open("/page/terms-use","null","width=900,height=750,
toolbar=no,scrollbars=no,location=no,resizable =yes");
window.moveTo(0,0);
window.resizeTo(screen.width,screen.height-100);
self.close();
}'; 

drupal_add_js($myscript, 'inline'); //change the 2nd param to 'theme' if $myscript points to a theme .js file
?>

查看頁面時,頁面在瀏覽器中顯示如下:

<!--?php
$myscript = 'function openWindow(){
var browser=navigator.appName;
if (browser==”Microsoft Internet Explorer”)
{
window.opener=self;

}
window.open("/page/terms-use","null","width=900,height=750,
toolbar=no,scrollbars=no,location=no,resizable =yes");
window.moveTo(0,0);
window.resizeTo(screen.width,screen.height-100);
self.close();
}'; 
drupal_add_js($myscript, 'inline'); //change the 2nd param to 'theme' if $myscript points to a theme .js file
?-->

我已經使用PHP過濾器模塊向頁面創建者用戶授予使用PHP的訪問權限,但是仍然發生了同樣的事情。 這是由於富文本編輯器嗎? 但是,為什么即使在PHP代碼模式下也會發生這種情況?

通常,這是通過自定義模塊或主題功能處理的。 但是,假設將其放入節點上的字段中,您的代碼應該可以工作。 問題可能是文本格式設置。 假設這是Drupal 7,則可以轉到/ admin / config / content / formats。 我假設您使用的是PHP格式。 因此,您將需要檢查此格式的設置,並確保啟用了PHP過濾器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM