skip to Main Content

I need help on making working HTML code when you click on a link, it goes to about:blank with code in it.

I did the following code below, but it redirects it automatically and the link doesn’t work when I click it.

<body>
  <script>
    const w = window.open() // access the "about:blank" window you've opened
    w.document.body.innerHTML = "<p style='Subscribe to NothingButTyler on YouTube!</p><iframe src='https://1v1.lol'></iframe>"
    // or access other parts to add more JS or CSS
    const style = w.document.createElement("link")
    link.href = "LINK_THAT_I_WANNA_GO_TO"
    link.rel = "stylesheet"
    w.document.head.appendChild(style)
  </script>
  <h1>Learn the Coding Experience!</h1>
  <p>Click <a href="LINK_THAT_I_WANNA_GO_TO" id="link" target="_blank">here</a> to see the ultimate coding experience.</p>

Is there any way to fix this? Thank you very much!

(Please note this question is not the same as mine! Mine includes a link and not redirected in a way.)

2

Answers


  1. The opening <p> tag is not closed correctly.

    Before:

    "<p style='Subscribe to NothingButTyler on YouTube!</p>
    

    After:

    "<p style=''>Subscribe to NothingButTyler on YouTube!</p>
    

    The <link> tag is for adding an external resource. Use <a> to make a clickable hyperlink.

    Login or Signup to reply.
  2. As far as i can see your problem stems from an error in your javascript.
    You create const ‘style’ instead of ‘link’, leading to an undeclared variable error.

    Try the following js code. (it executes on load right now, so you will have to add a button event if you want to open it by click).

    <body>
      <script>
        const w = window.open() // access the "about:blank" window you've opened
        w.document.body.innerHTML = "<p style='Subscribe to NothingButTyler on YouTube!</p><iframe src='https://1v1.lol'></iframe>"
        // or access other parts to add more JS or CSS
        const link = w.document.createElement("link")
        link.href = "https://example.com"
        link.rel = "stylesheet"
        w.document.head.appendChild(link)
        </script>
        <h1>Learn the Coding Experience!</h1>
        <p>Click <a href="LINK_THAT_I_WANNA_GO_TO" id="link" target="_blank">here</a> to see the ultimate coding experience.</p>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search