Advertisement
iGorNoiZe

Парсинг ссылки и подмена яндекс метрики

Jul 25th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. function setUrlParamsToLink() {
  2. if (window.location.search.substring(1)) {
  3. let url = window.location.search.substring(1).split('&');
  4. let urlParams = {};
  5. var urlPid, urlLid;
  6. url.forEach(function (entry) {
  7. urlParams[entry.split('=')[0]] = entry.split('=')[1];
  8. });
  9. console.log(urlParams['pid']);
  10. if(urlParams['pid']){
  11. urlPid = '&pid=' + urlParams['pid'];
  12. } else {
  13. urlPid = '';
  14. }
  15. if(urlParams['lid']){
  16. urlLid = '&lid=' + urlParams['lid'];
  17. } else {
  18. urlLid = '';
  19. }
  20. let getUrlParams = urlPid + urlLid;
  21. linkParams = document.getElementsByClassName("link-params");
  22. for (var i = 0; i < linkParams.length; i++) {
  23. var memory20 = linkParams[i].getAttribute("href") + getUrlParams;
  24. linkParams[i].setAttribute("href", memory20);
  25. }
  26. }
  27. }
  28. setUrlParamsToLink();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement