stop cross-domain IFRAME links to open in "_top" target - iframe

My page loads an IFRAME with content from another domain (and I don't have control over the content) that contains links with target="_top" attribute. My page gets completely replaced once the user clicks on one of these links. Since my page is a stateful web application it would confuse the user.
Is there a way/trick to stop those IFRAME links to do so? They should either (visually) load within the IFRAME or open in a new window.
I don't want to proxy the IFRAME using a server script and alter the HTML code since this would block any user cookies for the foreign domain.
Perhaps some special trick like nested IFRAMEs or whatever could do this?

Related

Get blocked url emitted from iframe in the parent

I have an iframe that has html/scripts injected into it that I have no control of. This iframe is part of a webview that we use in a mobile app so all redirects that occur need to go through the native levels. This is why popups need to remain blocked.
I see the URL of the new location in the console whenever I try to navigate away:
Blocked opening 'https://www.newwebsite.com/' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.
Is there someway to intercept the URL that is blocked from within the parent?
I have tried adding click event listeners to the <a> tags which solves some of my problems but this does not work for window.open calls.
Any tips or advice is would be very helpful. Thanks!

Backbone Project, How to navigate back when there is a iframe within the view?

How to navigate back when there is a iframe within the view?
After user clicks on a link to other pages from within the iframe, the browser history gets append on to it as well so that I cant use "window.history.back()" to go back, since "-1" will take user back within iframe and not the actual app itself.
What is a good way to solve this so that when back button pressed its the previous "route" and not the history of iframe history?
try doing something like this, from the Iframe:
window.top.history.back();
or
back to backbone app
This way you are accessing the Iframe's parent window history, not the Iframe itself. As long as you navigate to the Iframe from your SPA, this should work.

how to hide complete URL in browser address bar

I want to hide the sub directory and page information from my asp.net website URL. For example instead of displaying http://msdn.microsoft.com/en-us/library/aa479015.aspx I want to display something like http://msdn.microsoft.com/ always in user's browser address bar.
This requires a modern browser with History API support
history.pushState({}, false, "/");
If you call that on document load, you should achieve the desired effect
More information:
Manipulating the browser history | MDN
One way is to save your current handler information in a cookie, then in your global asax BeginRequest, and use HttpContext.Current.RemapHandler to remap their request to a different handler based on that cookie. Another way is to make use of an iframe on your page, this would be the easiest.
Although I don't think this is good style you can insert your pages into a frame (or iframe):
Start page of your domain, f.e. http://msdn.microsoft.com/:
<frameset rows="100%">
<frame src="/realstartpage.htm">
</frameset>
Now when the user navigates to another page, the address bar will not change because only the content of the frame is updated. Be aware that links to pages outside of your website should target the outermost frame:
Stackoverflow
But when a user comes in via a direct link to http://msdn.microsoft.com/en-us/library/aa479015.aspx then you would be required to forward to http://msdn.microsoft.com/ by a script and create the frameset (or iframe) f.e. by handling an URL parameter on the server.

Hidden controls, iframes or divs

What happens to the controls or the iframe or the div, which are hidden?
Do they get transferred to the user side?
Disabled:
does it get transferred to the user side?
What I want is,
an aspx page will be having many iframes to display different pages.
There will be many div tags to display CSS formatted information.
To understand what I mean by many:-
I have to transfer a complete website with 30 aspx pages into one single page!
I have simply combined everything resulting in one extremely huge page.
My concern is that on local host it loads fast, but when on online server accessed by numerous people for education purposes, the site (ONE PAGE) WILL SLOW DOWN terribly.
To overcome this I thought of using hidden and disable options.
What is an improved way of achieving the above?
Yes, it sounds silly but this is the requirement.
Edit:
Yes, I know id and server tag must be set, but what I am asking will the div tag be sent to the user's browser? One answer is no.
So can I enable them using JavaScript?
Like
document.getElementById(id).style.visibility="visible"
What if I disable them, and from coding of JavaScript enable them? Will they be loaded at the time of enabling?
Yes, they will be transferred if you hide them with CSS styles only.
Turn your iframe and your div container into a server control by adding an ID and the runat=server attribute. Then you can programmatically set the .Visible property to false which prevents the containers to the rendered into the DOM and therefore to be sent to the client.
Use ASP.NET panels. They render out as divs when visible. If they are set to visible = false the HTML and .NET controls inside them are not rendered to the browser.

Stop Master page refreshing while navigating between pages?

I'm using Master Page in my ASP.net application, in the master page I put a ContentPlaceHolder in Update Panel to support AJAX in child pages, the question is how to stop Refreshing "master page controls" while navigating between pages?
For navigation between pages I tried to use Response.Redirect, windows.location java script with no success, shall I use the Frames or IFrames instead of Master Pages to stop Refreshing?
any suggestion to solve this issue will be highly appreciated, Thanks in advance...
If you don't want the page to refresh when switching between "pages", you will not have any good solution using master page. As others have said in different words, the master page is just a common "template" that is used by different pages. The navigation between is just like calling different pages, and of course will reload the entire page, including the master page content.
A sollution I have used with Ajax is
to have each "page" as a user
controls, and put them all in an
UpdatePanel with visible="false".
Then for navigation between "pages", switch
visibility for the user controls
to show the right "page" control.
The alternative is to use iframe.
Neither of these solutions use MasterPage.
The MasterPage concept was designed to simplify a common look before Ajax was introduced in ASP.NET. After Ajax became popular, the demand for not refreshing the entire page has been more common.
A masterpage is nothing more than extending your "normal" page with (most of the time) the default layout of your application. The master page and the contentplaceholders are rendered as a full html page. When you navigate between pages it is the normal behavior that your whole page refreshes. This is how the web works.
Working with an iframe could solve your problem. However that has some other side effects:
The whole masterpage isn't useful anymore. The content around your iframe is the "masterpage".
With a masterpage you actually browse to another url, you also see in the url bar of your browser. When you work with an iframe you navigate within the iframe to another page. The url in your browser will stay the same. When the user of your application hits the refresh button it always starts again at the default page you assigned to your iframe in the html. Of course there are some workarounds
Anyway. It really depends on your application. There are multiple solutions to work around the refresh behavior.
Having a structure like the one you've explained:
Master
Child page 1
Child page 2
...
Then you cannot prevent the page from refreshing when you switch from page 1 to page 2 etc. for you have a single "page" entity (master content + selected page content) when it's rendered to the browser.
If you want to switch betweent different app views inside the very same page (so to prevent a complete page refresh) you could use a single page (the Master becomes quite useless) with an updatePanel in which you load the different views.
You can also use iFrames, but if you have to handle any type of communication between different parts of the page (some of which are inside iFrames) I would personally advice not to use them.

Resources