Jump to content

like-nix

Newbie
  • Posts

    2
  • Joined

  • Last visited

like-nix's Achievements

Explorer

Explorer (1/14)

0

Reputation

  1. все верно. Спасибо
  2. Здравствуйте, Я читал “Современный учебник JavaScript ->Документ и объекты страницы->Навигация по DOM-элементам”. Там в статье есть интерактивный пример навигации в главе “ Интерактивное путешествие”. Вот прямая ссылка https://learn.javascript.ru/traversing-dom#интерактивное-путешествие Мне стало интересно как он работает, и я его вытащил. И странно что у меня он не заработал так как был реализован на сайте. Я его немного исправил и он заработал. А точнее в конце скрипта файла travel.js, я заменил строки. Закомментировал setTimeout, и написал просто init: if (iframe.contentDocument.readyState == 'complete') { //setTimeout(init, 2000); init(); } else { iframe.contentWindow.onload = function() { //setTimeout(init, 2000); init(); }; } Вот функция init function init() { iframeDoc = iframe.contentDocument; currentElement = iframeDoc.documentElement; elem.onclick = function(e) { var dir = e.target.getAttribute('data-travel-dir'); if (!dir) return; if (currentElement && currentElement.style) { currentElement.style.border = ''; } currentElement = currentElement[dir]; updateControls(); if (currentElement && currentElement.style) { currentElement.style.border = '1px green solid'; } }; updateControls(); } Если запустить пример на который, я дал ссылку ниже, то в консоли отладки Google Chrome будет сообщение: Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match. Функция init запускается с SetTimeout, но у iframe атрибут contentDocument равен Exception: DOMException: Помогите пожалуйста разобраться зачем тут SetTimeout? Не понял как к теме прикрепить файл, поэтому даю ссылку на внешний источник на google drive https://drive.google.com/file/d/0B8TDEl003_XNNXZ3YkxBX2dGdDA/view?usp=sharing
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy