I’m new at HTML and JavaScript and I’m kind of totally lost, but I need a fast solution…
I created a website with some accordion buttons and what I would need is to open one specific accordion by clicking a link on an external website.
I read a lot into it, but it’s way over my skill level
What I got is that if you use an url link like www.domain.com/index.html?xyz you can create a javascript to “click” the accordion button for you. At least that’s one solution.
Like I said: I’m totally lost and helpless, but I need a solution fast and I’m hoping somebody can help me.
The HTML I have is:
<button class="tablink" id="defaultOpen" onclick="openPage('Home', this, 'transparent')">Home</button>
<button class="tablink" onclick="openPage('Downloads', this, 'transparent')">Downloads</button>
<button class="tablink" onclick="openPage('TracerSettings', this, 'transparent')">Tracer Settings</button>
<button class="tablink" onclick="openPage('Contact', this, 'transparent')">Contact</button>
<button class="tablink" onclick="openPage('Impressum_Datenschutz', this, 'transparent')">Impressum & Datenschutz</button>
<div class="tabcontent" id="Downloads">
<h1 class="PageTitel">Downloads und Software</h1>
</div>
For every button I a div with the ID of the button.
The JavaScript I’m using for the accordion:
function openPage(pageName, elmnt, color) {
// Hide all elements with class="tabcontent" by default */
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Remove the background color of all tablinks/buttons
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.backgroundColor = "";
}
// Show the specific tab content
document.getElementById(pageName).style.display = "block";
// Add the specific color to the button used to open the tab content
elmnt.style.backgroundColor = color;
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
It would be really great if somebody could help a small beginner and might be able to explain it to me.
Thanks a lot!