Как запустить скрипт после клика, но перед перенаправлением - PullRequest
0 голосов
/ 04 мая 2020

пожалуйста, помогите. У меня есть целевая страница с прямыми ссылками в теле на мой магазин. Я хочу запустить указанную c ссылку со скриптом аналитики в iframe, только для сбора статистики от пользователей, которые щелкнули ссылку

<a href="www.myshop.com">link</a>

Как я могу это сделать?

1 Ответ

0 голосов
/ 04 мая 2020

Ссылка: open-link-in-new-tab-or-window

Это может работать для вас:

$('a').click(function(e){
    e.preventDefault();
    var href = this.href;       
    console.log('go to the other page or highlight on the same page');
    location.href = href;
});
#demo {
width: 75%;
margin: 0 auto;
background-color: #fff;
-webkit-transition: all 1s linear;
}

#demo:target {
background-color: #ffa;
-webkit-transition: all 0.2s linear;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#demo">Link to a demo</a>
<div id="demo">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

Код основан на примере принятого ответа на этот пост: Выделите цель

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...