常见问题汇总

解决控制台对a标签href属性使用javascript:;导致的warning

  • 2020.05.15

问题描述

URLs starting with javascript: are a dangerous attack surface because it’s easy to accidentally include unsanitized output in a tag like <a href> and create a security hole.

In React 16.9, this pattern continues to work, but it will log a warning. If you use javascript: URLs for logic, try to use React event handlers instead.

解决方案

href属性值使用#!

// before
<a href="javascript:;" onClick={onClick}>我是一个超链接</a>

// after
<a href="#!" onClick={onClick}>我是一个超链接</a>
上次更新时间: 2020-05-28 16:12:00