Issue
The following code opens the anchor tag on a new window However, I do not want to reload the parent page. And also I want to have the ability to Open in a new tab on mouse right click (image below)
If I use href = {'javascript:'} it prevents the parent page from reloading however, when clicked on "Open in a new Tab", it opens on a new tab but url becomes about:blank#blocked
const handleClick = () => {
window.open(
href,
'newwindow',
`width=${window.outerWidth * 0.5}, height=${
window.outerHeight
}, left = ${window.outerWidth * 0.25} `
);
return false;
};
<a href = {href} onClick = {handleClick}> This is Url </a>
Desired result:
- By default, open in a new window.
- Prevent parent window from refreshing.
- Have ability to open on new tab on right click.
Solution
You need target="_blank" for this.
<a href="www.google.com" target="_blank">Click</a>
Answered By - Tushar Shahi

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.