drupal_add_js() issues I am facing some problems while using drupal_add_js() along with drupal_goto().

I am using hook_nodeapi() to capture a node prepare condition; inside the "prepare" case, I am adding the following JavaScript code, which I need to close a Lightbox window):

drupal_add_js('$(document).ready(function() {
  window.parent.location = "'.$base_url.'";
  window.parent.Shadowbox.close();
})', 'inline');


The problem is that if I add a drupal_goto() before or after drupal_add_js(), then the JavaScript is not included in my page source.

I hope I am able to explain my problem. Can anyone please point me towards why this happens? 

I know I can use JavaScript to implement drupal_goto() functionality, but in some cases the drupal_goto() comes from the drupal module itself and thus cannot be removed.
drupal_goto() alters the header of the page, then calls exit(). So if it's placed before the drupal_add_js(), the function will never be called, and if it's placed after, the header says "Go some place else," and you will be redirected as soon as possible, not waiting for jQuery to execute.

Why do you need to close the shadowbox in the first place if you are going to redirect the user somewhere else? It sounds like there's a fundamental problem to what you want to do.