Код: Выделить всё
/*doom.js*/
var info = {
title : "doom",
price : "59.99",
off : "0%"
};
< /code>
А моя HTML -страница - это та: < /p>
< /code>
У меня есть эта страница для всех моих игр, поэтому я использую метод получить метод, чтобы узнать, какой файл мне нужно прочитать. (game.html? id = doom) < /p>
У меня есть этот код, чтобы выбрать идентификатор и загрузить файл: < /p>
window.onload = function() {
id = getURLParameter('id');
loadGamefile("games/"+id+".js");
};
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
function loadGamefile(filename){
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref);
loadinformation();
}
function loadinformation(){
document.getElementById("title").innerHTML = info.title; //info.title is from the doom.js file
}
Подробнее здесь: https://stackoverflow.com/questions/373 ... access-var
Мобильная версия