The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
jQuery - Link in iframe to open in a new window in an iframe, but still on my page.
Discuss Link in iframe to open in a new window in an iframe, but still on my page. in the JavaScript Development forum on Dev Shed. Link in iframe to open in a new window in an iframe, but still on my page. JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 13th, 2012, 07:47 AM
|
|
|
|
jQuery - Link in iframe to open in a new window in an iframe, but still on my page.
I will explain it a bit.
mysite.com has an iframe with some links in it.
When you click a link in that iframe, it will open in the same iframe in mysite.com. This is not good, since I want one specific link in the iframe to open in a new window.
Not only do I want this link to open in a new window, but the new window has to be a page of my own site, with an iframe which displays the result of the clicked linked of the iframe on my homepage.
Hope you understand this, it's difficult to explain.
I am not familiar with jquery but i've searched and found something that I thought may help me a little. This is the closest topic on the web that i could find:
http://stackoverflow.com/questions/11193643/open-outgoing-link-in-iframe-by-default
I've tried the basic codes listed there to start, but i don't even know how to implement that correctly on my pages. For instance, i tried this to start:
On my index.php:
Code:
<a href="/result.php?link=http://www.google.nl">testlink.</a>
On result.php:
Code:
<iframe src="<?php echo $_GET['link']; ?>" />
As it says in the stackoverflow link i provided, but this doesn't work.
Here is my testpage.
http://www.onlineobjectives.com/vliegtest/
The iframe can be called with javascript or with the regular iframe code as you can see. I don't care for one or the other, whichever one will work the best i'll use.
If you select a flight and click 'zoeken' (which means 'search') - then it has to open the /result.php page, with an iframe which excutes the search.
__________________
woozy.
|

November 13th, 2012, 09:48 AM
|
|
|
|
Tried another way to get a bit of a start.
This method works for everyone in this thread:
http://www.codingforums.com/archive/index.php/t-85547.html
But leaves me with a blank iframe on the new page.
Confusion is complete right now.
|

November 13th, 2012, 08:00 PM
|
 |
Lost in code
|
|
|
|
Quote: | When you click a link in that iframe, it will open in the same iframe in mysite.com. This is not good, since I want one specific link in the iframe to open in a new window. |
If you have a link inside an iframe and you want it to open in the parent window instead of in the iframe, you can do so by specifying the target attribute in the HTML a tag for the link:
Code:
<a href="#" target="_parent">link</a>
Code:
<a href="#" target="_top">link</a>
If you want it to open in a new window, set the target to _blank.
Quote: | Not only do I want this link to open in a new window, but the new window has to be a page of my own site, with an iframe which displays the result of the clicked linked of the iframe on my homepage. |
Your approach with result.php is correct; you would simply modify the a tags to link to result.php instead of their original link.
However, based on the way you worded your post, I'm guessing that you don't have control over the contents or <a> tags inside the pages in your iframe, and in that case what you're trying to do is impossible.
|

November 14th, 2012, 04:11 AM
|
|
|
|
Hm that's too bad. Thanks for clearing it up.
|

November 14th, 2012, 04:33 AM
|
|
|
One thing though. Even the simple codes when i do control the link don't work at all. How is that? For instance i changed the testpage now, check it out:
http://www.onlineobjectives.com/vliegtest/
Only code i've used is this:
Code:
<p>
<a href="http://www.google.nl" target="vidframe">Dit is 3e test.</a>
</p>
<iframe name="vidframe" id="vidframe" src="" width='250px' height='250px'></iframe>
why doesn't this even work? According to every source on the web this has to work.
|

November 14th, 2012, 04:37 AM
|
|
|
|
aha, i think it had to do with the google link I used as a test site. I used another site and it works, so nevermind.
|

November 14th, 2012, 09:52 AM
|
|
|
|
It doesn't look like they are willing to change the iframe. So here's what i was thinking to solve this:
Page A:
- mydomain.com/form/
Where there is a form resembling the form the site in the iframe has. But this form is on my own site, with values resembling all the values of the iframe form. But the iframe with the 'original' form is not on this page!
Page B:
- mydomain.com/search/
When clicking 'submit' on my own form on page A, it needs to go to this page B. Page B is also my own page, but here you will find the iframe. The form in the iframe needs to be filled & submitted automatically when someone fills and submits my own form on page A (matching form values).
I think this would be possible, right? I'm a long time roboform user and this standalone program doesn't care if a form is in an iframe, it fills and submits everything automatically. I assume doing something like this on a website isn't working that much different?
I am now looking into CURL as this looks like it would do what i want, never used it before though so it's new to me. Would this work?
|

November 14th, 2012, 06:32 PM
|
 |
Lost in code
|
|
|
|
Quote: The form in the iframe needs to be filled & submitted automatically when someone fills and submits my own form on page A (matching form values).
I think this would be possible, right? I'm a long time roboform user and this standalone program doesn't care if a form is in an iframe, it fills and submits everything automatically. I assume doing something like this on a website isn't working that much different? |
No, that is not possible either. JavaScript from your website is not allowed to read or write data to an iframe if the iframe src points at a different website. All interaction between your parent page and the iframe page will be blocked if the domains of the URL are not identical.
If this were not the case, then your original approach would have been possible because you could have dynamically modified the contents of the iframe to change the URLs of the <a> tags.
The fact that roboforms is a standalone program is the reason why it can do this. A standalone program runs with full privileges on the user's computer. Your JavaScript code runs with extremely limited privileges.
Quote: | I am now looking into CURL as this looks like it would do what i want, never used it before though so it's new to me. Would this work? |
It IS possible to do this using cURL, or any server-side language for that matter. Effectively what you have to build is a proxy. The end user sends a request to your site, your site sends a request to the remote site, the remote site sends a response to your site, your site modifies the response and then sends it back to the end user.
Not only does this allow you to modify the HTML contents of the iframe on the server-side, but because the iframe src will be on the same domain as the parent page, you will be able to interact between the two with JavaScript also.
|

November 15th, 2012, 09:41 AM
|
|
|
Quote: | Originally Posted by E-Oreo It IS possible to do this using cURL, or any server-side language for that matter. Effectively what you have to build is a proxy. The end user sends a request to your site, your site sends a request to the remote site, the remote site sends a response to your site, your site modifies the response and then sends it back to the end user.
Not only does this allow you to modify the HTML contents of the iframe on the server-side, but because the iframe src will be on the same domain as the parent page, you will be able to interact between the two with JavaScript also. |
Good news, thanks for the clear answers. I've got some work to do!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|