Is it possible at all to write a plugin that loads a certain HTML page
but before the JS in that page starts running, the plugin overwrites
alert() and confirm() functions, so that once they get called by the
JS, the plugin can have control over the alert() and confirm() boxes.
e.g. the plugin would be able to not display these boxes at all or
some other trick i want to do.

and the redirection that is done by either with HTML meta tag or some
JS command such as top.location="http://..." by the JS code. is it
possible to prevent such a redirection/control it somehow.

please refer me to some documentation on this and please also tell me
whether it is doable in your opinion, so that i don't waste time if
it's totally hopeless.

thanks in advance.