简体   繁体   English

如何在 JavaScript 中使用 window.open 更改 css href?

[英]How to change css href using window.open in JavaScript?

I want to change CSS href using window.open in JavaScript.我想在 JavaScript 中使用window.open更改 CSS href

<a class="cssButton" id="Launch" target="_blank" data-baseref="Example/index.html?" href="Example/index.html?" >Launch Example</a>

change into变成

window.open(/* url goes here */);

with all attributes in css href above.具有上面 css href 中的所有属性。

You can accomplish what you want in two steps:您可以通过两个步骤完成您想要的:

1) Change your <a> element's target to 'new-win' or any name you want. 1)<a>元素的目标更改为'new-win'或您想要的任何名称。

<a id="Launch" target="new-win" href="Example/index.html?">Launch Example</a>

2) Create an event listener for the click event of the <a> element wherein to use window.open . 2)<a>元素的click事件创建一个事件监听器,其中使用window.open As arguments to window.open , pass the href and the target of the <a> element.作为window.open参数,传递href<a>元素的target

document.getElementById("Launch").addEventListener("click", function () {
  window.open(this.href, this.target);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM