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
The opening
<p>
tag is not closed correctly.Before:
After:
The
<link>
tag is for adding an external resource. Use<a>
to make a clickable hyperlink.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).