[英]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.