The key is not to replace anchor functionality with Javascript. Anchors are designed to take you to a new URL. If you have an anchor, use it as an anchor (eg, set a href
on it). Don't bind a click event that uses window.location
to redirect to a new url.
Your current anchor has no href
. So when you try and open it in a new tab, there's no surprise that nothing loads. You're literally opening nothing in the new tab.
If you really need to set the URL dynamically, then change the href of the element using javascript. For example:
document.getElementById('my-element').href = new_href;
It goes without saying that this needs to be done before the anchor is clicked (not on click). For example, on window.load
, or the completion of the function that generates the dynamic URL.