0

I have content type which has text field. Each node has its own javascript code which is set in to the text field. Text field is PHP Code format.

When I add this field to Views block site load ONLY the javascript in that text field. Whole other drupal content is not loaded. When I remove this field from views then site works normally.

This script works on full node but not in the Views. What can cause this? What ways to fix it?

Script is from Tradedoubler (third party advert) :

<script type="text/javascript">
  var uri = 'http://url.com' + new String (Math.random()).substring (2, 11);
  document.write('<sc'+'ript type="text/javascript" src="'+uri+'" charset=""></sc'+'ript>');
</script>
3
  • Why are you hacking things like that? And why PHP format for just a JS script? What does your Firebug / Chrome developer tools have to say about your issue?
    – Mołot
    Dec 27, 2013 at 11:15
  • This is for image banners which record user cliks. Third party provides this. I made my own text format which allows script tags, but after noticing this strange behavior I set it to PHP. Firebug did not tell anything usefull.
    – hene
    Dec 27, 2013 at 12:38
  • Code Per Node is designed for this.
    – Beebee
    Jan 26, 2017 at 16:20

1 Answer 1

0

Try using the Views PHP module. First, make the field with the javascript be excluded from the display (check the box for this, don't delete the field). Then add a php field to the view, and then have it print the field with the javascript via the replacement pattern. You can also use PHP to manipulate it, write more javacript, etc. This is the only way I have found to add javascript to view rows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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