Open a link in an iframe placed in a new window

时间:2016-07-11 18:58:09

标签: javascript php jquery html iframe

So this is my situation; I have a page that shows data from an xml. This page generates links dynamically based on the data it receives. Right now when I click these links, it opens a new tab/window with exactly what it needs to show.

However...

My problem: I need this to work slightly differently. I need these links to open in an iFrame inside a fixed page... What do I mean..? This should explain better

Page1 has many links with different URLs (generated by xml)

Page2 has a fixed url (like... http://www.dummysite.com/instructions). The lay out is a set of text instructions and an iFrame

When the user clicks a link in Page1, what needs to happen is: Page2 opens up with it's fixed url and the link the user clicked on (the XML generated link) opens up inside the iframe of Page2

I really don't know how to better explain this, and I don't even know what to search for answers.

Help me oh wise people of the internet, you're my only hope

1 个答案:

答案 0 :(得分:0)

To access an iframe that has the id "myIframe" in a a window you can use

var iframe = wnd.document.getElementById('myIframe')

To change its scr You can use iframe.src = url;

var wnd= window.open("", "", "width=400,height=400");
wnd.document.write('<iframe id="myIframe"src="https://bing.com" />');
wnd.document.getElementById('myIframe').src ="https://www.bing.com/search?q=cats";