Peacy
Peacy

Reputation: 96

Html and iFrames

Ok so the problem is that when you click on a link in the left iframe I'd like it to open in the right iframe. When you click on a link in the left sidebar for the first time this all works great. But when you would click for the second time on that link (in the left sidebar) it will open in a new browser tab. How can I make it work that it will open constantly in the right frame?.

Thanks in advance, Peacy

index.html http://pastebin.com/u6DqDA1q

left_frame.html http://pastebin.com/UuZYtdYs

Upvotes: 0

Views: 370

Answers (3)

min
min

Reputation: 1

I come to the same conclusion that it doesn't work the second time you click on the link. I'm not sure what the problem is, but here is the code for the 2 files, based on the suggestions by user1721135. http://pastebin.com/B2F2XseH and http://pastebin.com/6nZBXEU1

Upvotes: 0

user1721135
user1721135

Reputation: 7092

Yes, it should work just fine, the link in iframe 1 needs to have target equal to the name of the target iframe.

For example:

Iframe 1

<iframe src=""></iframe>

Target Iframe

<iframe name="iframe2"></iframe>

Content of Iframe 1

<a href="" target="iframe2">Link opens in iframe 2</a>

Also check this link i found

http://www.trans4mind.com/personal_development/HTMLGuide/iframes3.htm

Upvotes: 1

SnareChops
SnareChops

Reputation: 13347

Have you considered using AJAX to populate div's for the other side? This would help with platform compatibility as-well

<div id="left-side"></div>
<div id="right-side"></div>

left.html

<a onclick="OpenToRightSide('some-url')">some url text</a>

and in the main html parent file

function OpenToRightSide(url)
{
    var xmlhttp;
    if (window.XMLHttpRequest)xmlhttp=new XMLHttpRequest();
    else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET",url,true);
    xmlhttp.send(); 
    xmlhttp.onreadystatechange=function()
    {
        document.getElementById("right-side").innerHTML=xmlhttp.responseText;
    }
}

Upvotes: 0

Related Questions