1

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?

stecb
  • 14,478
  • 2
  • 50
  • 68
dov.amir
  • 11,489
  • 7
  • 45
  • 51
  • 2
    Java is _not_ JavaScript. How many times... – Bojangles Nov 21 '11 at 14:40
  • 1
    @JamWaffles what makes you think he's confusing the two? – jaybee Nov 21 '11 at 14:47
  • Because his question doesn't reference JavaScript in any way. Granted, it's part of a website that is likely to have JS on it somewhere, but the OP is talking about a _java_ app being opened in a new window. – Bojangles Nov 21 '11 at 14:49
  • Actualy I intentionally wrote javascript because I knew that the answer involves javascript (and all the answers prove that this is a js question) – dov.amir Nov 21 '11 at 15:32

3 Answers3

3

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:

  1. Check for the presence of a frame:

    if (top === self) { not in a frame } else { in a frame }

  2. 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.

James Hill
  • 60,353
  • 20
  • 145
  • 161
  • javascript can always be turned off by the user, so this will not 'ensure' that the app is running in an iframe, will it? Or am I missing something? – vascowhite Nov 21 '11 at 20:23
  • @vascowhite, you're correct - **ensure** was not the appropriate word to use. – James Hill Nov 21 '11 at 20:27
1

Check window.parent on load.

jaybee
  • 1,897
  • 2
  • 16
  • 29
1

With javascript you can detect if you are running inside an iframe. Look: How to identify if a webpage is being loaded inside an iframe or directly into the browser window?

Community
  • 1
  • 1
rodrigoap
  • 7,405
  • 35
  • 46