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.
This question is related to
javascript
html
onclick
Just use window.open()
:
window.open('Prosjektplan.pdf')
Anyway, what guys are saying on comments is true. You better use <a target="_blank">
instead of click events.
onclick="window.open('your_html', '_blank')"
you can use
<p><a href="/link/to/url" target="_blank"><button id="btn_id">Present Name </button></a></p>
The window.open method is prone to cause popup blockers to complain
A better approach is:
Put a form in the webpage with an id
<form action="theUrlToGoTo" method="post" target="yourTarget" id="yourFormName">
</form>
Then use:
function openYourRequiredPage() {
var theForm = document.getElementById("yourFormName");
theForm.submit();
}
and
onclick="Javascript: openYourRequiredPage()"
You can use
method="post"
or
method="get"
As you wish
Source: Stackoverflow.com