Не загружается JS без обновления страницы
Сделал переход между страницами без перезагрузки. Теперь, когда я подключил виджеты с Telegram, при переходе с одной страницы (index.html) на другую (archive.html) JS-скрипт не показывается, пока не обновлю страницу. Можно как то заставить JS активироваться без перезагрузки страницы?
import Swup from 'https://unpkg.com/swup@4?module';
const swup = new Swup();
/* Определите продолжительность перехода во время посещения страницы. */
html.is-changing .transition-fade {
transition: opacity 0.25s;
opacity: 1;
}
/* Определите стили для выгруженных страниц. */
html.is-animating .transition-fade {
opacity: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="icon" href="favicon.ico">
<link href="/css/swup.css" rel="stylesheet">
<script type="module" src="/js/swup.js"></script>
</head>
<body>
<main id="swup" class="transition-fade">
<h1>Welcome</h1>
<p>Lorem ipsum dolor sit amet.</p>
<a href="/index.html">Page2</a>
<script async src="https://telegram.org/js/telegram-widget.js?22" data-telegram-share-url="https://testtest" data-comment="Test" data-size="large"></script>
</main>
</body>
</html>
Ответы (1 шт):
Автор решения: Lafnian
→ Ссылка
Помог [коментарий],(Не загружается JS без обновления страницы), спасибо.
Оставлю, если у кого то будет такая проблема.
Scripts on the next page are not executed\
Swup doesn't insert new script tags by default. To run code after a page visit, you have a few options that are explained in the section on Reloading Scripts.\
- Trigger custom code using hooks
- Use the Head Plugin to insert new scripts into the head
- Use the Scripts Plugin to run existing and new scripts in head or body