React & Modern Frontend (445 Qs)•Part 11: Legacy Architecture, Migration Patterns & Historical Internals (354 - 445)
Can I use javascript urls in react16.9?
⚠️ DEPRECATED: As of React 19, javascript: URLs are no longer supported and may throw errors.
javascript
In React 16.9, `javascript:` URLs would log a warning in the console because URLs starting with `javascript:` are dangerous security vulnerabilities (XSS attacks).
javascript
const companyProfile = {
website: "javascript: alert('Your website is hacked')",
};
// This logged a warning in React 16.9
// Now blocked or throws error in modern React
<a href={companyProfile.website}>More details</a>;
markdown
**Modern Best Practice:**
- Never use `javascript:` URLs
- Use proper event handlers instead:
javascript
const handleClick = (e) => {
e.preventDefault();
// Your logic here
};
<a href="#" onClick={handleClick}>More details</a>
// Or better:
<button onClick={handleClick}>More details</button>