Javascript 如何同时使用onclick和target="_“空白”;
代码如下:Javascript 如何同时使用onclick和target="_“空白”;,javascript,html,onclick,Javascript,Html,Onclick,代码如下: <p class="downloadBoks" onclick="location.href='Prosjektplan.pdf'">Prosjektbeskrivelse</p> Prosjektbeskrivelse 这样可以正常工作,但它会在同一窗口中打开文件。我想应用target=“\u blank”。但在谷歌搜索了一番后,我还是想不出答案。只需使用: 不管怎样,男人们在评论中说的都是真的。您最好使用而不是单击事件。使用: 语法是: win
<p class="downloadBoks" onclick="location.href='Prosjektplan.pdf'">Prosjektbeskrivelse</p>
Prosjektbeskrivelse
这样可以正常工作,但它会在同一窗口中打开文件。我想应用target=“\u blank”。但在谷歌搜索了一番后,我还是想不出答案。只需使用:
不管怎样,男人们在评论中说的都是真的。您最好使用
而不是单击事件。使用:
语法是:
window.open(strUrl, strWindowName[, strWindowFeatures]);
您的代码应该具有:
window.open('Prosjektplan.pdf');
您的代码应该是:
<p class="downloadBoks"
onclick="window.open('Prosjektplan.pdf')">Prosjektbeskrivelse</p>
Prosjektbeskrivelse
window.open方法容易导致弹出窗口阻止程序投诉
更好的方法是:
在网页中放置一个id为的表单
然后使用:
function openYourRequiredPage() {
var theForm = document.getElementById("yourFormName");
theForm.submit();
}
及
onclick=“Javascript:openYourRequiredPage()”
你可以用
method=“post”
或
method=“get”
如您所愿,您可以使用
<p><a href="/link/to/url" target="_blank"><button id="btn_id">Present Name </button></a></p>
target=“\u blank”代表的是标签,而不是位置。href=正是我想要的东西,但不完全正确。target
attrib不再被弃用。参考号:;而a
比使用p
链接到使用javascript的资源更可取。哦,是的。。。a元素上的目标属性在早期版本的HTML中已被弃用,但不再被弃用,因为它在Web应用程序中非常有用,尤其是与iframe元素结合使用时。这也不起作用。它被检测为弹出窗口,并在所有主要浏览器中被阻止。请确保要打开的选项卡是https
function openYourRequiredPage() {
var theForm = document.getElementById("yourFormName");
theForm.submit();
<p><a href="/link/to/url" target="_blank"><button id="btn_id">Present Name </button></a></p>