JavaScript code before downloading a document

Hi,

I am creating a custom function, which basically a logic hook before downloading any document. I have seen many online tutorials on this but couldn’t ind any thing useful in my case.
Basically i am trying implement a document viewer to prevent downloading using jquery.
As a start i created the two files logic_hooks.php and DocumentsLogicHooks.php in custom/modules/Documents/
logic_hooks.php:

<?php // custom/modules/Documents/logic_hooks.php $hook_version = 1; $hook_array = Array(); $hook_array['before_save'] = Array(); $hook_array['before_save'][] = Array(1, 'Save Preview', 'custom/modules/Documents/DocumentsLogicHooks.php', 'DocumentsLogicHooks', 'before_save_method'); ?>

DocumentsLogicHooks.php:

<?php // custom/modules/Documents/DocumentsLogicHooks.php if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class DocumentsLogicHooks { function before_save_method($bean, $event, $arguments) { if((empty($bean->preview_c) && !empty($bean->document_revision_id))) { try { echo ""; } catch(ImagickException $e) { $GLOBALS['log']->fatal($e); } } } } As you can see i am implementing a simple alert before saving the document (downloading). But this doesn't work. Could any one help me out in creating a before download method executing a javascript or jquery code in it? It would be a great help if this is solved. Thanks in advance.