Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use both onclick and target="_blank"

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.

like image 257
Patidati Avatar asked Oct 25 '13 11:10

Patidati


People also ask

Can 1 Button have 2 onclick events?

So the answer is - yes you can :) However, I'd recommend to use unobtrusive JavaScript.. mixing js with HTML is just nasty.

Is Target _blank deprecated?

It looks like target="_blank" is still alright. It is listed as a browsing context keyword in the latest HTML5 draft.

What is the difference between target blank and target _blank?

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.

What does the reserved target name _blank signify?

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


1 Answers

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> 
like image 95
Praveen Kumar Purushothaman Avatar answered Sep 28 '22 17:09

Praveen Kumar Purushothaman