I am working on a java webapp that is displayed in an iframe inside a larger portal.
My webapp must always be inside the iframe of the outer portal, but when the user right clicks on one of my webapp’s links and does “open in new window/tab”, he sees my webapp as a standalone website in the new window.
How do I prevent seeing my app outside of the portal’s iframe?
The functionality you’re referring to is at the browser level and is therefore impossible to remove (i.e., the link option will always be there). There are several things you can do to ensure that your app is running inside a frame:
Check for the presence of a frame:
if (top === self) { not in a frame } else { in a frame }Disable the right click menu (ctrl + click will still work) Below is a simple example.
<body oncontextmenu="return false;">Note: Although I’m sure it goes without saying, if the user has disabled JavaScript, this approach will not work.