0

I have the following code, how I can get the html page provided by url and printed it to the console using getHtmlFunction() function when I press the button.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id = "getHTML">Get Html</button>
    <script>
        const getHTML = document.getElementById("getHTML");
        btnRepos.addEventListener("click",getHtmlFunction);
        const url = "https://www.google.com"
        
        function getHtmlFunction(){
        // what to do here
        }
    </script>
</body>
</html>
  • You cannot. you need to access sites that are CORS enabled and that will allow you to get their contents – mplungjan Feb 27 '22 at 19:38

0 Answers0