I'm trying to implement the following: the site has a certain menu, working on the onclick="followLink(event, this)" function. Everything, in principle, works fine, but on one of the pages - I just don't have javascript loaded, which should work with a certain player (it also uses javascript. That is, when I go to the page I see the necessary javascript in the links in the source code, but the player fulfills it, as if it does not exist at all.

The method of smooth page change:

 function followLink(event, link) { var nameLink = link.innerHTML; uploadContent(link.href+'&ajax=1'); history.pushState({title:nameLink, href:link.href}, null, link.href); updateTitle(nameLink); event.preventDefault(); } function updateTitle(title) { var link = document.createElement('link'); document.getElementsByTagName('head')[0].appendChild(link); link.setAttribute('type','text/css'); link.setAttribute('rel','stylesheet'); link.setAttribute('href','/templates/styles/player.css'); link.setAttribute('type','text/javascript'); link.setAttribute('rel','javascript'); link.setAttribute('href','/templates/js/jquery.jplayer.js'); var elm = document.getElementsByTagName('title')[0]; elm.DOM = title; } function uploadContent(link) { var cont = document.getElementById('content'); cont.innerHTML = loading.innerHTML; function createRequestObject() { processData:false if (typeof XMLHttpRequest === 'undefined') { XMLHttpRequest = function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} throw new Error("This browser does not support XMLHttpRequest."); }; } return new XMLHttpRequest(); } var http = createRequestObject(); if( http ) { http.open('get', link); http.onreadystatechange = function () { if(http.readyState == 4) { $("#content").css("display", "none"); $("#content").fadeOut(1000); $("#content").fadeIn(2000); cont.innerHTML = http.responseText; } } http.send(null); } else { document.location = link; } } window.addEventListener("popstate", function(e) { uploadContent(e.state.href); updateTitle(e.state.title); }, false ); 

  • In the samago player code does not occur anywhere e.stopPropagation ()? - Mihail
  • No ..... I refused the above described function with xmlhttprequest due to the fact that users have started a wild load on the processors. Now I understand with JQury, where the code and gluttony are many times less. However, this option mercilessly cuts out everything in the tags <script> - Ryan

1 answer 1

 function updateTitle(title) { var link = document.createElement('link'); document.getElementsByTagName('head')[0].appendChild(link); link.setAttribute('type','text/css'); link.setAttribute('rel','stylesheet'); link.setAttribute('href','/templates/styles/player.css'); link.setAttribute('type','text/javascript'); link.setAttribute('rel','javascript'); link.setAttribute('href','/templates/js/jquery.jplayer.js'); var elm = document.getElementsByTagName('title')[0]; elm.DOM = title; } 

This is why I do not understand this too much. It is necessary to do the top and bottom did not change so that well, even the menu, and the current is changing, the middle and all Java will be loaded once in the header, for example, and the load is changed several times.