0

is there a function in ColdFusion that detects whether or not a browser window is the top window? (Similar to (if (window == window.top)) in JavaScript)

The reason I ask is because I would like to make certain page elements present when the page is directly accessed by the user, and not present if my page is iframed.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
mobiman
  • 619
  • 1
  • 11
  • 26
  • Under what circumstances would the page be within an iframe? – Russ Oct 09 '12 at 03:40
  • We run an online games website, and sometimes other websites will iframe our games. I don't have a problem with this, but I don't want other unnecessary page elements to render if the user is only seeing the game. – mobiman Oct 09 '12 at 04:17

3 Answers3

4

CFML code runs on the CF server, whereas any considerations about browser windows obviously run on the client. CF is completely unaware of the UI configuration of the client system, all it sees is "a request". Indeed the requests don't even come from the client, they come from the web server which acts as a go-between for CF-serviced requests: CF has no interaction with the client itself.

The only information the web server gives to CF that in any way relates to the client browser is some of the stuff in the CGI scope, and obviously that's limited. And none of it relates to the configuration of browser windows / iframes.

You will need to solve this with Javascript (which I will add to the tags of your question).

To trigger different code to execute on CF given a certain browsing situation, you are going to need to use Javascript to add some information to the request to identify the situation to CF. This could be adding a parameter on the query string, or something like that.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • Ok, that makes sense. But I'm not sure what you mean by adding a parameter on the query string. Are you talking about the database query? What kind of parameter would I add? – mobiman Oct 09 '12 at 06:02
  • I'm guessing he means adding a URL parameter in the query string. I'm not sure how to accomplish this other than a redirect. – David Faber Oct 09 '12 at 11:03
0

If someone was 'wrapping' one of my products I'd want to know who and how so I could improve the experience for the user and the site owner. With that in mind, what I would do is automatically break out of any frames by default. I would then create a simple api and provide instructions to other webmasters on the proper way to include your content. Display different content once you've determined if your content is PROPERLY being included in another site. For webmasters that want to include your content:

  1. Provide recommended height/width for the iFrame so you can include your logo or ads with the content.
  2. Provide anything you want them to include in the query string to help track usage.
  3. You could even add fun stuff to your api to make your content look more integrated into the including website like reacting to url.bgcolor or url.bgimage.

You could go as simple as looking for and recording the value of some url variable like url.remoteSiteAddress or as complicated as registering the site and providing unique key. Of course there are other considerations to take into account to enforce the key. Being that you don't really care that the content is being displayed on a remote site, I suspect just recording a simple url variable is more your speed.

genericHCU
  • 4,394
  • 2
  • 22
  • 34
  • We're already recording the site URL's (using CGI.HTTP_REFERER) that are iframing our games, and it's working well so I don't see the need to change that. Especially since it's so easy for anyone to add a simple iframe to their site. – mobiman Oct 10 '12 at 14:55
  • HTTP_REFERER can have some wonky behavior so, use at your own risk. – genericHCU Oct 10 '12 at 15:04
  • Ok, I understand. But for our purposes it's not too big of a deal. Nothing critical, just checking to see where our traffic is coming from. – mobiman Oct 11 '12 at 08:17
-1

If a different website is putting your page in an iframe on their website, then you could use the CGI.HTTP_REFERRER variable to check if the website domain is yours or not, and load content as desired.

Russ
  • 1,931
  • 1
  • 14
  • 15
  • Thanks, but I tried that and ran into a problem. If the user clicks a link on say our Facebook page and is directed to our webpage, then the CGI.HTTP_REFERER value will be "http://www.facebook.com/". So even though the user is seeing the entire page (as opposed to an iFramed game), the code thinks the page is being iFramed. – mobiman Oct 09 '12 at 05:01
  • CGI.HTTP_REFERRER is probably the most unreliable cgi variable of all time and shouldn't be used for anything important. ever. http://stackoverflow.com/questions/6880659/in-what-cases-will-http-referer-be-empty – genericHCU Oct 09 '12 at 21:39