Reputation: 111
Hi guys!
I have a line of code:
<iframe id="ChildFrame" class="_page_frame_style" src=""></iframe>
So I have three buttons (id: "one", "two", "three").
And I need to change src of iframe by clicking on respective id.
Idea is:
1. When page is loaded no frame is displayed. (display:none)
2. When click on "one" button - shows one.html.
3. When click on "two" button - shows two.html. And so on...
4. Make a button to return ChildFrame into display:none.
I've been googling for it, but every try failed.
Thanks for each reply!
Upvotes: 1
Views: 148
Reputation: 211
here is the answer
$('#ChildFrame').attr('src', src_value)
and the src_value is the source link value that you want to set for your iframe element
and also have a look at this link:
Upvotes: 1
Reputation:
You can modify the HTML <iframe>
tag src
attribute in JavaScript using element.src
. Therefore, you can make a button that calls a function which makes the src of the <iframe>
change each time.
Additionally, you can make the iFrame hidden by default and use JavaScript to display it again when the button is pressed.
function changeIFrame(url) {
document.querySelector("iframe").src = url;
document.querySelector("iframe").setAttribute("style", "");
}
<button onclick="changeIFrame('/page1.html')">Page 1</button>
<button onclick="changeIFrame('/page2.html')">Page 2</button>
<iframe style="display:none;"></iframe>
Upvotes: 1