Introduction
Opening documents such as PDFs in a new window should be automated using JavaScript for the following reasons:
Users will often close the web browser when a PDF is opened, mistakenly believing the document has been opened in Adobe Reader
The attribute historically used to open a new window, target, has been removed from the HTML 4.01 Strict specification (it's now deprecated)
Opening a new window is a behaviour and should be moved to the behavioural layer.
Using JavaScript can also be particularly useful when a website is content managed. Rather than having to rely on site editors to remember to open a link to a PDF in a new window the process is handled by a simple JavaScript function.
The JavaScript
So you can see what we're aiming to do, check out this fully functioning example.
Registering an event
The first task is to create an event that occurs when the page has loaded. Rather than trying to execute a function call using within the HTML page we're going to use Simon Willison's addLoadEvent(func). This will allow us to add function calls once the page has loaded.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment