Hello.

I came across a very strange situation for me: I connected the js file with ajax handlers to the index.html file, everything works completely on my PC, but I’m coming from the phone and it doesn’t work. I checked for script support, inserted the js-code from the file directly into index.html - everything works both on the phone and on the PC.

<script type="text/javascript" src="/js/obrphp.js"></script> 

This is the js connection code of the file that is located inside the <head> in index.html.

Please tell me, what can this problem be connected with?

The problem with this code is:

 document.addEventListener('DOMContentLoaded', e => { //Поиск людей document.querySelector('#txtsearchobch').addEventListener('keydown', function(e){ if('key' in e) { if(e.key.toLowerCase() !== 'enter') { return; } } else { if(e.keyCode !== 13) { return; } } var txtsearchobch = $("#txtsearchobch").val(); window.location.replace('?search='+ txtsearchobch +'#searchus'); }); }); 
  • If you want to tinker, you can try this thing vorlonjs.com . In general, it is embarrassing that type="text/javascript" . If doctype html5 , then you should remove the type, but I doubt that the problem is this. And of course, the problem may be in the phone itself, in the browser that is used, etc. - olegatro
  • @IvanPshenitsyn problem is in the very first line of the code - Sasha Osipov
  • @ SashaOsipov sure that the switch function is supported? - olegatro
  • I see the problem: e => { syntax, which is very poorly supported. If you do not have transformation libraries, you need to rewrite. - Ivan Pshenitsyn
  • one
    @IvanPshenitsyn agree, babel wrote for good reason. - olegatro

1 answer 1

Apparently, the problem is in using the new syntax from the ECMAScript 6 standard, namely the “arrow functions” (arrow functions):

 document.addEventListener('DOMContentLoaded', e => { //Поиск людей ... }); 

It is better to use cross-browser option.

 document.addEventListener('DOMContentLoaded', function(e){ //Поиск людей ... }); 

A detailed table describing ECMAScript 6 support for browsers and platforms can be found here: http://kangax.imtqy.com/compat-table/es6/

If you want to use exactly the new syntax - you need to use one of the available compilers from ES6 to ES5 ( traceur , babel ).

  • Thank you so much, otherwise I was already tortured with this) - Sasha Osipov