javascript - window.open on a-tag for new tab -
i using code open new tab:
<a href="javascript:window.open('https://example.com','_blank')">linktext</a>
the new page loaded within new tab @ source page shown [object]
instead of link. wrong?
i not want use
<a href="https://example.com" target="_blank")">linktext</a>
because generate list of links , target page called differently each link. flexible way me use give syntax.
edit: generated linklist:
<a href="javascript:window.open('https://example.com','_blank')">linktext 1</a> <a href="javascript:jsfunc1(param1)">linktext 2</a> <a href="javascript:jsfunc2(param2,param3)">linktext 3</a>
the href attribute generated. table.
the point of javascript:
scheme url generate replacement page javascript. isn't designed run javascript in response client while leaving page alone — event handlers for.
the new "page" seeing result of converting reference new window string.
this best avoided not using javascript this:
<a href="https://example.com" target='_blank'>linktext</a>
you can avoiding using javascript:
scheme uris , binding js separately (with sensible fallback in href):
<a href="https://example.com">linktext</a> <script> document.queryselector("a").addeventlistener("click", your_function); function your_function(evt) { evt.preventdefault(); // whatever else want function } </script>
if want use javascript url scheme (which, suggested above, dirty hack), can ensure script returns nothing using void
operator:
<a href="javascript:void (window.open('https://example.com','_blank'))">linktext</a>
Comments
Post a Comment