Clive Atkins Clive Atkins - 4 months ago 22
Javascript Question

Jquery attr Open New Window

I am trying to open a URL in Jquery which works fine however I would like the window to open in a target _new way.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(location).attr('href', 'http://www.google.com');
</script>


I have tried adding

.attr('target','new');


and some variations but to no joy. Thanks in advance.

Answer

If you want open url in new page you can use:

window.open("http://stackoverflow.com/", '_blank');

Demo: https://jsfiddle.net/cmedina/mxfqo12o/

Comments