1

In my React application, I need to open a page in new window when clicking a link in the Bootstrap table. Please help me with the example.

Earlier, I have set the table cell in a variable and assigned it to dataformat in the table header. How can I change this code to open in new window?

Update: After making the code changes as suggested below, the page is opening in a new tab but the testid is not passing to the other page (which is fetched using this.props.testid).

column1 = (cell, row) => {
  let link = `${cell}`
  return (
    <Link to={{                
      pathname: '/test',
      state: {
        testId: row.testid
      }
    }} target="_blank" rel='noopener noreferrer'>
      {cell}
    </Link>
}
2
  • Could you share your tried example ? or where get you stuck? Commented Nov 13, 2019 at 7:30
  • Added the sample code. Commented Nov 13, 2019 at 8:42

3 Answers 3

1

Maybe try this:

 <td onClick={()=> window.open("LinkToOpen", "_blank")}>Link</td>
Sign up to request clarification or add additional context in comments.

Comments

1

You can define anchor tage like this in react to open in new window

Define rel="noopener noreferrer" to avoid warning in react.

<a href="https://google.com" rel="noopener noreferrer" target="_blank">google</a>

Comments

1

Use a regular link but style it as a table cell:

<a style={{display: "table-cell"}} href="someLink" target="_blank">text</a>

Comments

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.