Auto-Launch a file attachment
In the Notes Client there is an option when designing a form to tell it to launch the first attachment when a document is opened. How about doing this in the browser? I've thought of two ways of doing it:
- Meta-Tags
- JavaScript
Place the following line in the $$HTMLHead field (or its equivalent in R5)
path := @ReplaceSubstring(@Subset(@DBName; -1); "\\"; "/");
file := @ReplaceSubstring(@Subset(@AttachmentNames; 1); " "; "+");
@If(@Attachments;
"<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=/" + path + "/0/" + @Text(@DocumentUniqueID) + "/$file/" + file + "\">"
;"")
When the page is opened it automatically opens the first attachment. What happens next depends on the browser, the file type and the user's preferences. In IE, if the file is an office document it will probably launch automatically. Text (.txt) files should open on all browsers as should Adobe Acrobat (.pdf) files and standard HTML files. The user also has the option to tell the browser what to do with each type of file.
2. JavaScript This method is number two as it is not as fool proof as the meta-tag method. Place the following somewhere in your header ($$HTMLHead field) and as soon as the browser encounters the JavaScript that is generated it will redirect to the attachment.
path := @ReplaceSubstring(@Subset(@DBName; -1); "\\"; "/");
file := @ReplaceSubstring(@Subset(@AttachmentNames; 1); " "; "+");
@If(@Attachments;
"<script type=\"text/javascript\">"+@NewLine+
"<!-- "+@NewLine+
"location.replace(\'/" + path + "/0/" + @Text(@DocumentUniqueID) + "/$file/" + file + "\');"+@NewLine+
" -->"+@NewLine+
"</script>"
;"")
JavaScript that is generated:
<script type="text/javascript">
location.replace( '/dir/db.nsf/0/1d45..49de/$file/test.txt' );
</script>
Note: This could be done simply by changing the value of location.href but there is a good reason not to. If you simply change the location href then the "redirect" page is still in the browser's history and every time the user hits the back button they will simply re-run the above script and end up back in the page they were already in. Hence, "breaking the back button" = very annoying. Using the replace method tells the browser not to remember the current page and make the back button go to the page they were in before the "redirect" page.
Jake you are a Legend EOM
Reply
Typo in Second Example
In the second example there is a duplicate + sign in the string. Not a big deal but it means you can't just paste the code into the header and run.
There is a + sign at the end of line 7 and the begining of line 8.
-Mike
p.s. Also i'm using IE 6 and both examples break the back button for me.
Reply
Re: Typo in Second Example
Hi Jake,
It works with a "simple" page but if i open a office document or a pdf document, the back button is broken.
With an attachment of a text file it works too.
Somebody got any idea ?
Reply
Works great and does not break back button in IE6
Works great and does not break back button in IE6
Thanks again for another superb solution to a very common domino issue!
Reply
And in Notes?
Sorry, but how would this actually work in Notes? - I know the AttachmentLaunch command and I know how to get the names of the attachments etc., but how do you select one of the attachments for it to be launched?
Thanks, Pascal
Reply
Thanks Jake - you saved me a lot of frustration
I wasted several hours trying to do this using Webqueryopen and javascript, with no luck, then stumbled on a link to this page in Notes.net. Muchas Gracias, Capitan!
Reply
Auto-Launch a file attachment
Thanks for the solution. This works great.
Reply
THANK YOU, THANK YOU, THANKYOU
This was exactly what the Dr ordered. Thanks.
Question: Is there anyway to do this to make sure that it doesn't open PPT, but just opens in a browser?
Reply
Thanks
This one created alot of problem.The above code is working fine.but i want to open in other window
Reply
Brilliant
Thanks a lot. Had an urgent requirement to do this for a client. Without this it would have taken me hours (if at all).
Reply