location.href
will only change the URL of the current window. In order to open a new tab or window, its better to use window.open
. I tested it in Safari specifically (and Chrome) and it is working in both browsers.
<a href="/somepage.html" onclick="javascript:ref()">CLICK ME</a>
<script type="text/javascript">
function ref() {
window.open('http://www.google.com', '_blank');
}
</script>
The way you had it written, somepage.html will open in a new tab and the current page will redirect to google. If you want it that way just switch the URLs around like so:
<a href="www.google.com" onclick="javascript:ref()">CLICK ME</a>
<script type="text/javascript">
function ref() {
window.open('/somepage.html', '_blank');
}
</script>
A side note, I found out that Safari allows user to handle how they want windows opening, whether it be a new window or a tab, and unfortunately we do not have any control over that.