M
M
Maxim Lesnikov2016-05-12 18:06:16
Yandex.Metrica
Maxim Lesnikov, 2016-05-12 18:06:16

Forwarding depending on the city?

There is a small script, I can't change it for automatic redirection.

<script src="http://yastatic.net/jquery/2.1.1/jquery.min.js"></script>
  <script type="text/javascript"> 
  window.onload = function () {
    if(ymaps.geolocation.region == 'Санкт-Петербург и Ленинградская область'){
       jQuery(".region-city").text('spb.example.ru');
       jQuery(".region-city-href").attr('href', 'http://spb.example.ru');
     } 
  else if (ymaps.geolocation.region == 'Краснодарский край'){
       jQuery(".region-city").text('krasnodar.example.ru');
       jQuery(".region-city-href").attr('href', 'http://example.ru');
     }
  
</script>
<script src="http://api-maps.yandex.ru/2.0-stable/?load=package.standard&lang=ru-RU" type="text/javascript"></script>

Changed like this:
else if (ymaps.geolocation.region == 'Краснодарский край'){
       jQuery(".region-city").text('krasnodar.example.ru');
       jQuery(".region-city-href").header('Location: http://krasnodar.example.ru');
     }

But I feel that all this is not the same. And the redirect doesn't work.
Who can suggest a solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yakov Vylegzhanin, 2016-05-13
@vylegzhanin

Instead of this
this

document.location.href="http://krasnodar.example.ru";

Y
yaskin, 2018-08-09
@yaskin

I think that first you need to connect the script " api-maps.yandex.ru " , and then pull methods from it in your script, and not vice versa

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question