Code is as following:
<p class="downloadBoks" onclick="location.href='Prosjektplan.pdf'">Prosjektbeskrivelse</p>
Works fine like this, but it opens the file in the same window. I want to apply the target="_blank". But after some googleing I still can't figure it out.
So the answer is - yes you can :) However, I'd recommend to use unobtrusive JavaScript.. mixing js with HTML is just nasty.
It looks like target="_blank" is still alright. It is listed as a browsing context keyword in the latest HTML5 draft.
The difference: target="_blank" is a special keyword that will open links in a new tab every time. target="blank" will open the first-clicked link in a new tab, but any future links that share target="blank" will open in that same newly-opened tab.
Use "_blank" According to the HTML5 Spec: A valid browsing context name is any string with at least one character that does not start with a U+005F LOW LINE character. (Names starting with an underscore are reserved for special keywords.)
Instead use window.open()
:
The syntax is:
window.open(strUrl, strWindowName[, strWindowFeatures]);
Your code should have:
window.open('Prosjektplan.pdf');
Your code should be:
<p class="downloadBoks" onclick="window.open('Prosjektplan.pdf')">Prosjektbeskrivelse</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With