How to detect if my iFrame is used by another website?

How to detect if my iFrame is used by another website?



I make web games. I upload them to portals like Newgrounds. They are being embedded as iFrames on those sites. However, I noticed that other sites "steal" the games by embedding the iFrames on their own websites. Is there any code I can run in my iFrame to detect which site I am embedded on?



I keep searching and a lot of threads say something like


if (window.top.location.hostname != "myhost.com")
console.log("Not on myhost");



but that doesn't seem to work these days due to DOMExceptions. Anything else I can do? Or did I miss something obvious here?




1 Answer
1



First, you can simply tell if the page is embedded in an iframe by checking window.top itself:


window.top


if (window != window.top)
console.log("In an iframe");



I think the code you posted should only get an exception if the parent page is in a different domain. So you could just check for the error:


try
var = window.top.location.hostname;
catch (e)
console.log("In an iframe from another domain");






My game is posted as an iFrame in both cases. Also, Newgrounds seems to host the game on a server with a different domain than their frontend. So sadly, neither of those tests will distinguish between the original and fraudulent website.

– Krystian
Sep 18 '18 at 0:59



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)