skip to Main Content

I want to open an html file which is in my local, in a new tab on button click in react component. I am trying to import the html file and then use window.open() method of javascript for this purpose. But for importing the html file I need html-loader plugin. But I get this when I try to install the plugin using npm – enter image description here

Is there any other way to open an html file in a new tab on button click in react js and if not, why is the html-loader plugin not getting installed?

2

Answers


  1. This can be d one with Vanilla JavaScript, I don’t believe you should need the html-loader plugin:

    button onClick="Open()">Link</button>
     
    <script>
        function Open() {
            window.open("https://www.google.com", "_blank");
        }
    </script>
    

    html-loader is used to read HTML files in as strings (see the npm package page here). As for why your installation isn’t working, it appears that you are having issues with some other packages you have installed (ant-design icons, material UI, and react). Perhaps try removing all conflicting packages with npm uninstall [package-name] and then subsequently reinstalling the ones you need.

    Login or Signup to reply.
  2. If you use react-router-dom, you might find the following code helpful.

    <Link target={"_blank"} to="your-link">Your Link</Link>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search