Minion
Minion

Reputation: 2567

Open link inside of a iframe in new window within the iframe

I have this:

Div element (like a bar, with some text and a logo)

Iframe with a page that I cannot modify (in this example: google.com)

What I need is to "catch" (or anything else), all links that user click with mouseweel (or right click it and open it in new window), then, open that link in another window with a div element and an iframe which loads the link inside the iframe, I mean, in a new page exactly like the first, with the div and the iframe.

If user clicks normally any link, it just opens the link inside the iframe (as iframe usually does).

I've found a code that changes all links in website and it opens all of them in new window referring the url of the link to PHP with a parameter, but I don't want to open all links in new window, by default all links in the page it opens inside of a iframe (_self) in html, but if the user wants to open it in new window, I want to allow that, but opening it new window with a div element and an iframe which loads the link inside the iframe...

Upvotes: 0

Views: 1950

Answers (2)

Mooseman
Mooseman

Reputation: 18891

From your current question, I understand that you want links to NOT open in a new tab, and to replace the page currently open in the iframe.

Short answer: not possible.

Full answer:
1) Links using target="_blank" cannot be edited inside an iframe hosted on a separate site. This is because of the Same Origin Policy.
2) In theory, you cannot ever override what the user wants, even if you could control the iframe content. Specifically, when a user clicks "open in a new tab," this can never be overridden.

Upvotes: 1

Tomáš Zato
Tomáš Zato

Reputation: 53319

It is not possible to interact with anything in iframe within different domain. You must use HTTP PHP proxy that will edit the page you display so all links DO redirect on your site.
So the solution would be to have a PHP script that downloads the site you display in iframe, chang ALL links from http://differentsite.com/path/file.php to http://mysite.com/script.php?path=path/file.php so that if the user clicks the link, he gets in your IFRAME view again.
This is how HTTP proxies do work.

Upvotes: 1

Related Questions