I am trying to add some JavaScript to a Drupal Page to open a link in a popup without address bar etc. I have since learned that you can't just embed JS in the "Full HTML" view. (script tag gets commented out with HTML comments) So I have used the PHP mode of entry using the PHP function drupal_add_js(), but the php code gets commented out with HTML comments when the HTML is rendered. i.e
<?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
?>
When page is viewed, it shows up in the browser as follows:
<!--?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
?-->
I have used PHP Filter module to give the Page creator user access to use PHP, but still the same thing happens. Is this because of a rich text editor? But why does it happen even in PHP code mode?