Я новичок. Я пытаюсь создать ссылку на другую страницу, открыв определенную вкладку
For Example i have 2 page (index.html and goto.html)
In my index.html there is 3 tab (London, Paris, and Tokyo) if i press go to tab london button in goto page it will send me to page index and open london tab and if i press go to tab paris button in goto page it will send me to page index and open paris tab etc.
это мой код index.html
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
body {font-family: Arial;}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body>
<div class = "tab">
<button class = "tablinks" onclick = "openCity(event, 'London')" id = "defaultOpen">London</button>
<button class = "tablinks" onclick = "openCity(event, 'Paris')" id = "bb">Paris</button>
<button class = "tablinks" onclick = "openCity(event, 'Tokyo')" id = "cc">Tokyo</button>
</div>
<div id = "London" class = "tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id = "Paris" class = "tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id = "Tokyo" class = "tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
// Get the element with id = "defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
</body>
</html>
вот мой код goto.html
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>In this example, we use JavaScript to "click" on the London button, to open the tab on page load.</p>
<div class = "tab">
<a href = "index.html#defaultOpen"> <button type = "button" name = "button">go to tab London</button> </a>
<a href = "index.html#bb"> <button type = "button" name = "button">go to tab Paris</button> </a>
<a href = "index.html#cc"> <button type = "button" name = "button">go to tab Tokyo</button> </a>
</div>
</body>
</html>



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Просто добавьте эту часть в свой код.
<a href = "index.html#defaultOpen" target = "_blank">
Это должно работать
Это работает, но после загрузки происходит автоматическая прокрутка вниз страницы (нижнего колонтитула).
Источник: https://www.w3schools.com/howto/howto_js_tabs.asp
Показывать вкладку по умолчанию
Чтобы открыть определенную вкладку при загрузке страницы, используйте JavaScript, чтобы «щелкнуть» по указанной кнопке вкладки:
<button class = "tablinks" onclick = "openCity(event, 'London')" id = "defaultOpen">London</button>
<button class = "tablinks" onclick = "openCity(event, 'Paris')" id = "defaultOpen">Paris</button>
<button class = "tablinks" onclick = "openCity(event, 'Tokyo')" id = "defaultOpen">Tokyo</button>
<script>
// Get the element with id = "defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
Не новая вкладка браузера. Если вы видите в моем index.html. есть 3 вкладки с контентом (Лондон, Париж и Токио)
Не новая вкладка браузера. Если вы видите в моем index.html. есть 3 вкладки с контентом (Лондон, Париж и Токио). И если я открываю индексную страницу в браузере, по умолчанию открывается лондонский контент. Я создаю страницу перехода с помощью кнопки 3, если я нажимаю кнопку перехода к парижу, я хочу, чтобы она перенаправлялась на страницу индекса с открытым по умолчанию содержимым парижа
Хорошо, извините за это. Думаю, я нашел ваш ответ: Показывать вкладку по умолчанию Чтобы открыть определенную вкладку при загрузке страницы, используйте JavaScript, чтобы «щелкнуть» по указанной кнопке вкладки: Пример <button class = "tablinks" onclick = "openCity (event, 'Лондон ') "id = " defaultOpen "> Лондон </button> <script> // Получить элемент с id = " defaultOpen "и щелкнуть по нему document.getElementById (" defaultOpen "). click (); </script> источник: w3schools.com/howto/howto_js_tabs.asp
Просто измените onclick = "openCity (event, 'London')" с Лондона на Париж или Токио, и вкладка изменится.
Если вы посмотрите на мой код, я использую этот код, но ничего не происходит. он просто открывает страницу в обычном режиме. если нажать, перейти на вкладку Париж или Токио, она все равно откроется на вкладке Лондон