e.target.href无法在firefox中运行

时间:2016-12-01 09:17:01

标签: javascript firefox reactjs events

e.target.href在firefox中不起作用。这仅适用于chrome。我尝试了问题的解决方案(event.target not working on Firefox),但仍然没有在firefox上工作。我还需要添加更多内容吗?

app.js

showModal(e) {
    if (!e) {
      e = window.event;
    }
    e.preventDefault();
    const event = e.target || e.srcElement;
    const url = event.href;
    console.log('url', url, event.href);
    const redirectTo = url.substring(url.lastIndexOf('/') + 1);
    this.setState({ show: true });
    this.context.router.transitionTo(redirectTo);
  } 

<Nav
  showModal={(e) => this.showModal(e)}
  hideModal={() => this.hideModal()}
  show={this.state.show}
  onHide={() => this.hideModal()}
/>

Nav.js

<button
  className="btn btn-default"
  onClick={(e) => props.showModal(e)}
>
 <Link to={{ pathname: '/signup' }}>
   {props.intl.formatMessage({ id: 'nav.registration.text' }) }
 </Link>
</button>

1 个答案:

答案 0 :(得分:1)

尝试使用run_as_udp

getAttribute()

   const tgt = e.target || e.srcElement;
   const url = tgt.getAttribute('href');
   console.log('url', url, tgt);