I have implemented this code snippet to prevent my page from being iframed:
window.onload = function(){
try {
if (window.parent && window.parent.location.hostname !== "app.herokuapp.com"){
throw new Error();
}
catch (e){
//do something
}
}
Although it works perfectly, I encountered an issue when trying to include more values to compare the hostname with. My intention was to add my custom domain name like this:
window.onload = function(){
try {
if (window.parent && (window.parent.location.hostname !=="app.herokuapp.com"
|| window.parent.location.hostname !== "www.app.com"
|| window.parent.location.hostname !== "localhost")){
throw new Error();
}
catch (e){
//do something
}
}
However, this logic always returns true and ends up throwing an error. Can someone guide me on how to fix this? I only want to throw an error if the hostname does not match these specific strings but it seems to throw an error regardless of the condition. Any assistance would be greatly appreciated as I am new to coding. Thank you!
P.S. I included "localhost" for local testing before deployment to Heroku.