【发布时间】:2013-06-21 03:15:31
【问题描述】:
我正在尝试向 Drupal 页面添加一些 JavaScript,以便在没有地址栏等的弹出窗口中打开链接。我已经了解到您不能只将 JS 嵌入“完整 HTML”视图中。 (脚本标签被 HTML cmets 注释掉)所以我使用 PHP 函数 drupal_add_js() 使用 PHP 输入模式,但是在呈现 HTML 时,php 代码会被 HTML cmets 注释掉。 IE
<?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 代码模式下也会发生呢?
【问题讨论】:
标签: php javascript drupal