logo

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:

  1. Meta-Tags
  2. JavaScript
1. Meta Tags - Using the Refresh meta-tag we can tell the browser to redirect the page to the chosen attachment.

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.

Feedback

  1. Jake you are a Legend EOM

  2. 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.

    1. 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 ?

  3. 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!

    1. 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

  4. 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!

  5. Auto-Launch a file attachment

    Thanks for the solution. This works great.

  6. 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?

  7. Thanks

    This one created alot of problem.The above code is working fine.but i want to open in other window

    • avatar
    • Scott H
    • Wed 3 Dec 2008

    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).

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Views"

« Previous Article Next Article »
URL Syntax for advanced field level searching   Quick edit document link

About This Article

Author: Jake Howlett
Category: Views
Keywords: file; attachment; launch;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »