2

e.target.href does not work in firefox. This only works in chrome. I tried following question's solution (event.target not working on Firefox) but still not working on firefox. Do i have to add something more?

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>
Community
  • 1
  • 1
Serenity
  • 3,884
  • 6
  • 44
  • 87

1 Answers1

1

Try using getAttribute()

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

showModal(e) {
    if (!e) {
      e = window.event;
    }
    e.preventDefault();
    const tgt = e.target || e.srcElement;
    const url = tgt.getAttribute('href');
    console.log('url', url, tgt);
    const redirectTo = url.substring(url.lastIndexOf('/') + 1);
    this.setState({ show: true });
    this.context.router.transitionTo(redirectTo);
  } 
zer00ne
  • 41,936
  • 6
  • 41
  • 68
  • I tried that too. I got null in firefox but it works in chrome and also i dont need to manipulate string. – Serenity Dec 01 '16 at 09:34
  • There's more than one way to skin a cat--try: `var xHref = tgt.getAttributeNode("href").value` – zer00ne Dec 01 '16 at 10:36