0

When button is clicked a blank page opens in a new tab. I would like to be able to click and get new tab to open with to different sites that are shown.

I discovered that having the link like below works:

btnClick() {
        window.open("https://www.google.com");
    } 
....................
<ButtonComponent cssClass='e-link' onClick={this.btnClick.bind(this)}>Go to google</ButtonComponent>

import { enableRipple } from '@syncfusion/ej2-base';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
class App extends React.Component {
    // Click Event.
    btnClick() {
        window.open();
    }
    render() {
        return (<div>
                <ButtonComponent cssClass='e-link' onClick={this.btnClick.bind("https://www.google.com")}>Go to google</ButtonComponent>
            </div>);
(<div>
                <ButtonComponent cssClass='e-link' onClick={this.btnClick.bind("https://www.yahoo.com")}>Go to yahoo</ButtonComponent>
            </div>);
    }
}
ReactDom.render(<App />, document.getElementById('button'));

no errors, just does not link to expected websites.

1 Answer 1

2

I believe you are using bind incorrectly. You do not pass the function parameters in bind, to pass a function with parameters in onClick() you use an arrow function. try the following code:

import { enableRipple } from "@syncfusion/ej2-base";
import { ButtonComponent } from "@syncfusion/ej2-react-buttons";
import * as React from "react";
import * as ReactDom from "react-dom";
enableRipple(true);
class App extends React.Component {
  constructor(props) {
    super(props)
    this.btnClick = this.btnClick.bind(this)
  } 

  btnClick(url) {
    window.open(url);
  }
  render() {
    return (<div>
      <ButtonComponent cssClass='e-link' onClick={() => this.btnClick("https://www.google.com")}>Go to google</ButtonComponent>
    </div>);
  }
}
ReactDom.render(<App />, document.getElementById("button"));
Sign up to request clarification or add additional context in comments.

1 Comment

No real need to use bind() when method is called in anonymous arrow function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.