What hook should I use to attach a script to a content type?
It depends on how you want to approach it. Clive's question is still relevant, Javascript redirects are neither great or optimal. However, if it must redirect based on a User Agent, Javascript might be the only option.

I would advise you to do the agent detection on the client side, as the server value may not always be accurate. Your code above won't work.

To load a script based on content type, you can do:

function mytheme_preprocess_node(&amp;$variables) {
  if ($variables['node']-&gt;type == 'mytype') {
    $variables['#attached']['js'][] = array(args);

    // or

    drupal_add_js('path/to/script.js');
  }
}


Your script itself also needs to be in a closure:

/**
 * @file
 */
(function () {

  "use strict";

  // All the JavaScript for this file.

})();


If jQuery or the Drupal scope is needed:

/**
 * @file
 */
(function ($, Drupal) {

  "use strict";

  // All the JavaScript for this file.

})(jQuery, Drupal);


See the docs page for more:


https://www.drupal.org/docs/7/api/javascript-api/managing-javascript-in-drupal-7
https://www.drupal.org/docs/develop/standards/javascript/javascript-coding-standards