How to restrict JS applied to a block only to block visible pages?
Using hook_block you can show the js wherever the block renders.

function hook_block($op = 'list', $delta = 0) {
   $block['content'] = 
   switch($op){
     case 'view':
      switch ($delta) {
        case 'header_block'://block name
        //here you add that js
          drupal_add_js(drupal_get_path('module', 'mymodule').'/sample.js');
          $block['content'] = theme('header_theme');
          break;       
      }         
      break;
   }
}