var utm = 'utm_term' var number = (window.location.toString().substr(window.location.toString().indexOf(utm + '=') + utm.length + 1, 50)).toLowerCase(); 

With the help of UTM-tag I pull out the value. If it is encoded, for example, this way:

 %D0%BA%D1%83%D0%BF%D0%B8%D1%82%D1%8C+%D0%B0%D0%B9%D1%84%D0%BE%D0%BD+6s 

I can not decode it with the decodeURI(str) method.

I can decode this way:

 decodeURI('%D0%BA%D1%83%D0%BF%D0%B8%D1%82%D1%8C+%D0%B0%D0%B9%D1%84%D0%BE%D0%BD+6s') 

That is, directly, but if you try decodeURI(number) , then nothing happens.

  • What do you want to do? What should be in the number? - Robert Dampilon
  • test.com/utm_term=key + word word = keyword, but basically the meaning of the label is: test.com / ... number, respectively, is the same. I need to decode it. - Lamer_2005

1 answer 1

You get "d0%ba%d1%83%d0%bf%d0%b8%d1%82%d1%8c+%d0%b0%d0%b9%d" , which is not very much equal to "%D0%BA%D1%83%D0%BF%D0%B8%D1%82%D1%8C+%D0%B0%D0%B9%D1%84%D0%BE%D0%BD+6s" .

If you want to parse the request in the URL, then, in fact, parse to be honest:

 var query = {}; location.search.substr(1).split("&").forEach(function(item) {query[item.split("=")[0]] = decodeURIComponent(item.split("=")[1])}) 

And then refer to the parameter query.utm_term , there will be your line "купить+айфон+6s" .

  • So. Does not work. First, I need to refer to the number, not utm_term, and, secondly, if I use the number, the variable returns undefined. Help me figure it out :( - Lamer_2005
  • @ Lamer_2005 Give the full URL. - Athari
  • up-context.ru/… - Lamer_2005
  • @ Lamer_2005 And what number do you need to get? - Athari
  • number? I need utm tag (buy + iphone + 6s) - Lamer_2005