Iframe links not to open in iframe - html

i have iframe that shows content from the page that is not mine. In that iframe exists some links. When user clicks on links, they open inside iframe. I want them to open in current window (parent window).
I have found solution to add
target="_parent"
to links, but i cant do that, becouse iframed page is not mine, and i cant edit that page.
Is there some way to do this, to open links from iframe in parent window?
Or js/jquery code to find all links on that page and add them attribut target?

Unfortunatley it is not possible to query the content of an <iframe> which origin is from a different server. The only thing what you could do is to "proxy" the page through a server-side script (with PHP or something) before outputting it:
request the page using "cURL" or something similar
parse the content for your needs (like setting the target-attribute on all links)
output it back to the page's iframe
Finally the <iframe> could look like this: <iframe src="myproxy.php"></iframe>

Related

How to access iframe internal url when user goes to next page in iframe only (inside iframe)

how to retrieve the url from an iframe, when a user goes or clicks to next page inside iframe.
i mean for website which allows x-frame-options.
(src attribute is on external server page)
Eg:<iframe src="http://www.google.com"></iframe>
An user types a word in google's search engine and clicks on search button (inside iframe) the iframe renders a new page about the search page and again the user clicks on some link inside it, iframe renders a new page ,I want to retrieve the url for which the user click on it inside the iframe.
The only way to do this would be via Javascript. If you give the iframe an id, such as iframeId, you can do something like:
document.getElementById("iframeId").contentWindow.location.‌​href
I googled on other website,but there is no solution for this,iframe tag is built to view contents of the page only,like frameset.
As developers we need to disable external clicking from the user inside the iframe content as it violates some hacking from other website content.

Anchor not working in iframe, but works fine outside of it

For a web site I'm trying to improve, I have an anchor in an IFrame document. One the main page, the anchor tag does not respond. On other pages which also embed this same iframe document, it does respond. By itself, all links in the iframe document work when the page is loaded directly. Also, if I trim significant content from the main page, the anchor links work. I found no errors in the web developer log. I'm using FF 31.0, but IE didn't work any better. Also, the page is HTML 5.
Rather than post the actual HTML, please see page at
dreamfloatmassagespa.com (this is the main page)
and dreamfloatmassagespa.com/FloatingPage.html (this is one of the working pages)
I've tried adding the sandbox attribute, but FF doesn't care in this case. Both the IFrame and the parent frame refer to locations on the same domain. The links in question point to actual web locations and not Javascript functions.
Your div with class .row are above everything in your main content, that's why you cant click in any anchor inside the main content in the mainPage.html. Probably you did some mistake in your css in the MainPage.html.

how can I navigate to a new page without reloading part of the current page?

I have a mybb forum, and a plugin that adds a public/private chat to the bottom of the forum (it adds a div before </body>).
I would like to navigate the forum without reloading the chat.
In this question, Josh Stodola explains how to change the url.
In this question, there is a small JavaScript code to change the url.
I've also read about HTML5 iframes, but I still can't imagine how can I use it all together.
Should the chat be inside an iframe? an iframe inside the forum? should the forum be inside an iframe, and the chat into another? And those 2 iframes, inside a new page???
I'm messed up...
You should have a window containing chat and an iframe for your content. This will allow you to navigate your forum and only reload the iframe vs the top frame.
<body><iframe src="someurl"></iframe><div>Chat</div></body>
A few things to note: doing it this way will not change the address bar while you navigate and this makes users confused when they try to link to pages and it takes them to the home page or wherever they started browsing your forum.
If you want to do something more fancy checkout pjax. It will let you change urls for the whole page while only loading certain content.

Is there any way to request a page without displaying it?

If you link to something downloadable with a simple <a href, the user will download the file while staying on the current page. You can get this behavior with files that the browser has no plugin for (like .bin), or by sending a content-disposition header to force downloading.
Is there any method or header which keeps the user on the current page while still requesting the page? The idea is that the user clicks a link, the request is made, but the page doesn't change—like when downloading a file.
This could be done with an iframe I guess, which is not really pretty and makes another request when loading the page. Javascript is another obvious answer, but that's actually the reason for asking this question: compatibility with JS-less clients.
A form with the method set to HEAD is another ugly solution, but doesn't work anyway. Chromium ignores the method and simply performs a GET request...
Anymore ideas?
You could place an iframe on your page that is hidden. Then, give that iframe and id.
Use this id as the target of a link to the file you want to pull down.
I've created a demo at http://jsfiddle.net/dancrumb/N87nL/ to show you how this would work. Just style the iframe as being invisible and you're good to go
The page will load in the iframe, you'll stay on your page, it doesn't require JS. Oh boy!
Note that the iFrame doesn't have an initial value for src, so no request is made on page load.

Can someone explain iFrames?

My understanding of the iFrame is that the content inside is exactly what is included in the src. I've seen numerous widgets like Facebook etc that use an iFrame.
When I try using an iFrame, I have an HTML file with only a div and some content inside, no head, body, etc. Just the content in HTML. But the iFrame always loads the entire page and ends up giving me a recursive iFrame within an iFrame.
I don't see how this is since my HTML file that is referenced in the iFrame is just content and nothing else. I'm not including a header, footer but all that gets displayed anyway.
I've seen where people are talking about scrolling the iFrame to a certain section and even using the div's id in the src and setting the scrolling=no. This works, but my iFrame content will reload based on user input and once it reloads it returns to the top-left portion of the page inside the iFrame.
This doesn't make any sense. Maybe this is supposed to be a widget or something?
Edit for SD to show some formatted code:
#Surreal Dreams
That's the strange thing. I'm using web2py so it might be something inherent in the backend that's causing that. The html file literally is a div wrapper with some elements inside. But I think the web2py is adding the header in there even though I'm not extending any kind of layout. I eventually did get it to work correctly by referencing the same html file saved offsite at another url. There it displayed properly without web2py interfering with the html structure.
What was happening before, I had code like this:
{{extend 'layout.html'}}
<div class="wrapper">
<page content>
<aside id="iFrame wrapper">
<iframe src="/rates.html"></iframe>
</aside>
</div>
And that's the basic structure of the web2py page where inside layout you have all your headers, footers, etc. Well what was happening is that it would generate the entire page, and where you get to the iFrame, it generates the page again inside that iFrame, and then on down to the iFrame again, which continues to infinity rendering the page inside each iFrame's page.
An iframe will always load an entire Web page, referenced in your iframe's src attribute. Even if your file only contains a div, I believe the browser considers it a full page and automatically adds a head and body.
"I've seen where people are talking about scrolling the iFrame to a certain section" => right, once the page in the iframe is loaded, you can use JavaScript to access and manipulate its DOM:
var myIframe = parent.document.getElementById("myIframe");
var window = myIframe.contentWindow;