0

I would like to run some jquery within a Basic page content type node and the only place that I can place this code is within the Body section when within the Edit Basic page. After placing the following at the bottom of the Body section like the below: jQuery(window).unload( function () { alert("Bye now!"); } );

It errors off so that it appears that it does not have jQuery included within this content type. I tried putting a link to Jquery before calling jQuery but the link to it also errors off. How can I execute jQuery within a Basic page content type node?

0

I am not sure, but You can try to change filter to Full HTML, or the second method, create template file for that content type like node--NAMEOFNODETYPE.tpl.php and clear cache and put your javascript code inside it.

example:

<div>
     // Here YOUR JAVASCRIPT CODE
     <?php print render($content['body']); ?>
</div>

Or another method, in template_preprocces_page you can check: for all nodes by one type - just check:

$node = menu_get_object();
if($node->type == "your type") {
  drupal_add_js('YOUR CODE', 'inline');
}

for only one node by nid:

$node = menu_get_object();
if($node->nid == YOUR NID) {
  drupal_add_js('YOUR CODE', 'inline');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.