使用javascript的target_blank属性

时间:2017-06-27 12:43:06

标签: javascript jquery html5 twitter-bootstrap css3

document.getElementById("mahacareer").onclick = function () {
	location.href = "http://www.mahacareermitra.in";
};
<a href="" target="_blank" id="mahacareer">Access the portal</a>

你好,我想在新标签页面上打开上面的链接,当我点击它时。我们使用带有标签的target =“_ blank”属性,但我想将该属性与JavaScript一起使用。

1 个答案:

答案 0 :(得分:0)

您可以使用

window.open('http://www.mahacareermitra.in','_blank');

您可以在java脚本中使用 SetAttribute 功能。

<a href=""  id="mahacareer">Access the portal</a>

试试这个

  document.getElementById("mahacareer").setAttribute("target", "_blank");