I have a HTML page where I have two IFrames, and there are two buttons controlling which of them is visible.
Here is the index.html
:
<!DOCTYPE html>
<html>
<head>
<title>MyPage</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body onload="init()">
<div class="main">
<div class="leftbar">
<button id="btn_1" class="leftbar-button" onclick="openTab(event, 'sec1')">Section1</button>
<button id="btn_2" class="leftbar-button" onclick="openTab(event, 'sec2')">Section2</button>
</div>
<div id="sec1" class="tabcontent">
<iframe src="section1.html"></iframe>
</div>
<div id="sec2" class="tabcontent">
<iframe src="section2.html"></iframe>
</div>
</div>
<div id="clear" class="clear" style="clear: both; height: 0;"></div>
<script src="main.js"></script>
</body>
</html>
Here is the main.js
:
function onSwInit()
{
// Set the home page to be displayed
document.getElementById("sec1").style.display = "block";
document.getElementById("btn_1").className += " active";
}
function openTab(evt, tabName)
{
// Hide all content
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++)
{
tabcontent[i].style.display = "none";
}
// Display the clicked section
tablinks = document.getElementsByClassName("leftbar-button");
for (i = 0; i < tablinks.length; i++)
{
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
Now, as one can see, by default, the page begins with btn_1 active and the corresponding IFrame section1.html
visible. Now the problem is, suppose I want to share the URL of the page with the IFrame section2.html
visible, how do I do it?
I am fine with a HTML, Javascript or PHP solution.