This JavaScript is executed if page it is on in the admin area is the one to be loaded however it does not execute if another page in the admin is loaded first and then that page is loaded.
$fields->addFieldToTab("Root.Zooph", new LiteralField('CustomCode'.$i++,'
<script type="text/javascript">
/* <![CDATA[ */
alert('Hello World');
/* ]]> */
</script>
'));
I think the problem may be that JavaScript loaded with AJAX is not being executed.
Any ideas?