Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server-side detection that a page is shown inside an IFrame

Tags:

asp.net

iframe

Is it possible to determine - server-side - whether a page has been loaded within an IFrame?

When certain errors happen in my application the user gets redirected to Default.aspx and an error message is shown. The text of that error message gets set in session by exception handling code. The error message gets cleared from session once it has been shown.

However, part of my application has to use an IFrame (it's doing a 3D Secure card payment check, which mandates an IFrame in order to display the card provider's authentication UI). If an error takes place during this process my redirect takes effect within the IFrame. I am using JavaScript to detect this and reload Default.aspx correctly, but this means that I get two Page_Loads in rapid succession, and the error message only gets shown on the first one (and then cleared).

like image 255
Richard Ev Avatar asked Apr 07 '09 13:04

Richard Ev


People also ask

How do you check if a page is inside an iframe?

In short, to check if a page is in an iframe, you need to compare the object's location with the window object's parent location. If they are equal, then the page is not in an iframe; otherwise, a page is in an iframe.


1 Answers

You can do it in client side: How to identify if a webpage is being loaded inside an iframe or directly into the browser window?

The workaround i found is put some identifier into querystring of a url opened inside iframe.

like image 124
Afonso França Avatar answered Sep 21 '22 13:09

Afonso França