skip to Main Content

I want to code something to fetch and run the code using a predetermined link, which will likely by a GitHub raw code link. Would it be possible to code this in html?

To be entirely honest, I mainly code in scratch using turbowarp. I’m trying to broaden my horizons but I don’t know much about coding and this is the start.

2

Answers


  1. You can not code this in html because you don’t code in html, you design html (it’s a tagong language not a coding lqnguage).

    Anyway, to do this, if yoy want to get a full page in to your page you can use iframe. But if you need to get some custom html without refreshing the page ajax (using in javascript) would be best option

    Login or Signup to reply.
  2. Here’s an example of how you could do it:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Code Fetcher and Runner</title>
    </head>
    <body>
      <button id="runButton">Run Code</button>
      <pre id="output"></pre>
    
      <script>
        document.getElementById('runButton').addEventListener('click', () => {
          const codeLink = 'YOUR_RAW_GITHUB_CODE_LINK_HERE'; // Replace with your actual code link
          fetch(codeLink)
            .then(response => response.text())
            .then(code => {
              try {
                eval(code); // Run the fetched code
                document.getElementById('output').textContent = 'Code executed successfully';
              } catch (error) {
                document.getElementById('output').textContent = 'Error: ' + error.message;
              }
            })
            .catch(error => {
              document.getElementById('output').textContent = 'Error fetching code: ' + error.message;
            });
        });
      </script>
    </body>
    </html>
    

    Replace 'YOUR_RAW_GITHUB_CODE_LINK_HERE' with the actual link to your GitHub raw code. However, keep in mind that using eval() to run arbitrary code fetched from the internet can be risky in terms of security. Make sure you trust the source of the code you’re fetching.

    Also, note that this example is very basic and not suitable for all types of code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search