So, I'm trying to make one of my website pages open in an about:blank URL before/when it's opened. But, my code isn't working for some reason even when I have it embeded in my index.html, here is my code so far:
function onl oad(){
let inFrame
try {
inFrame = window !== top
} catch (e) {
inFrame = true
}
if (!inFrame && !navigator.userAgent.includes("Firefox")) {
const popup = open("about:blank", "_blank")
if (!popup || popup.closed) {
alert("Popups are disabled!")
} else {
const doc = popup.document
const iframe = doc.createElement("iframe")
const style = iframe.style
const img = doc.createElement("link")
img.rel = "icon"
img.href = "https://google.com/favicon.ico"
doc.title = "Google"
iframe.src = location.href
style.position = "fixed"
style.top = style.bottom = style.left = style.right = 0
style.border = style.outline = "none"
style.width = style.height = "100%"
doc.body.appendChild(iframe)
location.replace("https://google.com")
}
}
}```
Can anyone help me?
CodePudding user response:
I can't see you whole index.html but I tried your code by putting it on index.html script tag and call onl oad() with having about.html page in my directory and it worked the only problem I got is popup was blocked by browser please check if that's the case enable it.
CodePudding user response:
in onLoad
function , can you please explain the try block. if the try block is equating window
object to a variable or a string, then that is the error. please re-check it. if possible provide some more details in code.