本文介绍了如何使用onclick和target =" _blank"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

 < p class =downloadBoksonclick =location.href ='Prosjektplan。 PDF'> Prosjektbeskrivelse< / p为H. 

正常工作,但它在同一窗口中打开文件。我想应用target =_ blank。但在经过一些googleing之后,我仍然无法弄清楚。 使用: >

语法是: strWindowFeatures]);

您的代码应该有:

  window.open( 'Prosjektplan.pdf'); 

您的代码应该是:

 < p class =downloadBoks
onclick =window.open('Prosjektplan.pdf')> Prosjektbeskrivelse< / p>


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.

解决方案

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>

这篇关于如何使用onclick和target =&quot; _blank&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:56