Prevent iframe from loading "src" page upon refreshing - html

I'm creating a static website and I am using iframes. The problem is, when I navigate to another page, say for example, this code for the iframe:
<iframe marginheight="0" align=top src="aboutus1.php" frameborder=0 scrolling=no border=0 WIDTH=800 framespacing=0 id="bodyframeid" name="bodyframename" onLoad="autoResize('bodyframeid');>" ></iframe>
The src attribute is pointing to aboutsus1.php. Now, when I navigate to another page, for example, I go to aboutus2.php then I reload the page, it goes back to aboutus1.php which is executed by src="aboutus1.php". My question is, how do I stay on the current page (aboutus2.php) even if I reload the page?
EDIT:
Click here for live example
Click the link above. First page you will see is About CTI. Now, try clicking on Partners menu then refresh the page. It goes back to About CTI page. How do I prevent it from going back to About CTI page when the page reload?

You could store the current page location in a session, and on reload load the url stored in the session. But you'd need some server side technology. In just html you don't store things. You might also be able to use a GET value.

You can't. By reloading the page you are loading a completely new page that just happens to come from the same resource as the previous page.
You can't avoid reloading the iframe when you are reloading the main page, but you can make it reload the same page again.
If you want to load a specific page in the iframe, you need to send information to the main page what to put in the iframe src. You can for example send that information in a query string, or put it in a cookie.

If you have in your iframe the documents from the same domain (same origin), or you can set the Access-Control-Allow-Origin headers on displayed page, you can detect iframe src change, and save the current URL (cookie, localStorage or anything you have), and restore it on page load.

Related

How to make iFrame behave exactly as if one were accessing the source site directly?

I am working on a site for a Client and they want to display the following URL in an iFrame:
https://www.vigrxplus.com/ct/3134
If you access that site directly, it will show the Promo code on the source website.
However, if you access that site via an iFrame, it will not show the Promo code on the source website:
https://jsfiddle.net/qc3zvo0b/
<iframe width="100%" height="1000" src="https://www.vigrxplus.com/ct/3134"></iframe>
(Make sure to test the iFrame without prior Cookies from having previously visited the source website directly.)
Attempting to enable all sandbox features for iFrame did not fix this.
The source site also seems to do some kind of redirect.
So how can this be fixed such that the iFrame behaves just like visiting the site directly?

Iframe is not showing the correct page

How comes I can't use an Iframe for the url http://www.ahv-services.ch/reschweb/rentenform.aspx?
<iframe frameborder="0" height="600px" scrolling="no" src="http://www.ahv-services.ch/reschweb/rentenform.aspx" width="100%"></iframe>
Firefox is showing me that the URL of the Iframe is http://www.ahv-services.ch/errors/error02.htm. This is also the page that is getting displayed in my browser but as you see in src attribute I am not looking for this page.
Edit: Even when you click on that link, it redirects you to the error page. Only when you copy & paste the link, it will show you the correct page.
Presumably, www.ahv-services.ch is examining the referer header sent by the browser (no, you can't supress it) and redirecting if it looks like a third party site is linking directly to that page.
Look at the error message you get (via Google Translate):
The calling web server is not registered for the use of this service. The Web services under www.ahv-services.ch were commissioned by the IGAKIS (www.igakis.ch) by Mathys & Scheitlin AG (www.ms.ch developed). The IGAKIS provides the services generally after registration. For more information or an application for a registration, please contact www.ms.ch or www.igakis.ch.
As you said in your question clicking on the link redirects you to the error page, I can confirm this happens for me too.
This means that there is not a problem with your iframe or any of the code on your page, it is the page at http://www.ahv-services.ch/reschweb/rentenform.aspx which is broken.
If you have access to this website then I would recommend you look into debugging this to see if there is an error in the code. If you do not have access to this then I recommend you get in contact with an admin who does.

How to restrict content of an IFrame to a particular domain from the iFrame

I want to use an iFrame to display the content of another web site (not mine) but I don't want to display other sites in that iFrame. For example, if the SRC for the iFrame is www.site.com then if a visitor clicks a link in that site that opens to another website, I want to prevent it and perhaps display a blank page or redirect back to the specified site.
The site hosting the iFrame uses Apache/PHP on a VPS.
I need to be able to restrict the iFrame content to what was originally specified. If this cannot be done using iFrame what else could work?
There is a similar post that does not work this way... only works on the content page and does nothing to prevent the host iFrame from controlling the content domain.

Iframe isn't displayed in IE on some URLs

I have simple html code:
<iframe src="http://public.bullhornstaffing.com" width="500" height="700"></iframe>
<iframe src="http://public.bullhornstaffing.com/JobBoard/Standard/default.cfm?privateLabelID=9076" width="500" height="700"></iframe>
The first iframe displayed excellent in all browsers, but second iframe isn't displayed in IE instead of the page I see the text "Site Not Found. The site your are trying to find does not exist."
But when I try to open iframe url in the browser directly - everything works as it is necessary.
There is method to correct it?
The URL of the second iframe gets redirected to http://public.bullhornstaffing.com/JobBoard/Standard/BHContent_JobOpportunities.cfm and for some reason, the server responds to it differently when accessed on IE via iframe (or otherwise as embedded). What you get is technically a normal server response, just with special content.
It is at the discretion of server admin to do such things, e.g. in an attempt at preventing framing, though this behavior might be unintentional. Contact the server admin.

What would cause an iframe to keep loading its parent page?

So this is quite the odd situation.... I have an iframe on a .cshtml page that is continuously loading the full content of the page that the iframe is on. This is the code for the iframe:
<iframe src="#Url.Content("~/dir/file.html")" width="100%" height="100%" scrolling="yes" />
The directory for the file is correct and the file.html file displays correctly without error when it is opened by itself. Also, I have tried using a different test.html file in place of file.html so the error cannot be within that file. Removing the iframe tag obviously stops this issue from occurring.
The other really interesting part about this issue is that I have a working version of the application that this .cshtml file belongs to and I have compared the corresponding .cshtml files and they are identical so I am really bewildered by this. Has anybody ever experienced a situation like this? The iframe literally just keeps reloading the .cshtml file within the iframe until I tell the browser to stop loading so you end up with a page with an iframe, that has a page withing the iframe, that has a page within the iframe, so on and so forth.
The answer to this question lies within the authentication for the application. When the iframe would make a call to file.html it would receive a redirect back to the .cshtml page which of course had the iframe on it so you can see where the loop comes into play. The solution of course then is to change the security settings to allow it to call to file.html as it needs to be displayed there. Thanks anyway.