HTML redirects not working using this sandbox code

Trying to create a sandbox for simulating a bunch of html files, (some of which are nested within others in this format for example

function redirectToProcessor(event) {
            event.preventDefault();
            window.location.href = 'video-processor.html';
        }

But when using the html code below (the sandbox’s code), its only rendering one page and not redirecting when the right buttons are clicked. Tried everything, if someone can figure out what I am doing wrong that will be very helpful. The above code is part of the html files I tried to use with it, but it just isn’t working.

For it to be able to simulate htmls even with redirects, no redirects happening.

const fileList = document.getElementById('fileList');
const fileInput = document.getElementById('fileInput');
const tabs = document.getElementById('tabs');
const codeArea = document.getElementById('codeArea');
const previewFrame = document.getElementById('previewFrame');

let files = {};
let currentFile = null;

fileInput.addEventListener('change', (event) => {
  const newFiles = event.target.files;
  for (let file of newFiles) {
    const reader = new FileReader();
    reader.onload = (e) => {
      files[file.name] = e.target.result;
      updateFileList();
      createTab(file.name);
    };
    reader.readAsText(file);
  }
});

function updateFileList() {
  fileList.innerHTML = '';
  for (let fileName in files) {
    const li = document.createElement('li');
    li.textContent = fileName;
    li.onclick = () => openFile(fileName);
    fileList.appendChild(li);
  }
}

function createTab(fileName) {
  const tab = document.createElement('div');
  tab.className = 'tab';
  tab.textContent = fileName;
  tab.onclick = () => openFile(fileName);
  tabs.appendChild(tab);
}

function openFile(fileName) {
  currentFile = fileName;
  codeArea.value = files[fileName];
  updateTabs();
  updatePreview(fileName);
  history.pushState({
    file: fileName
  }, '', `#${fileName}`);
}

function updateTabs() {
  Array.from(tabs.children).forEach(tab => {
    tab.classList.toggle('active', tab.textContent === currentFile);
  });
}

function updatePreview(fileName) {
  const blob = new Blob([files[fileName]], {
    type: 'text/html'
  });
  const url = URL.createObjectURL(blob);
  previewFrame.src = url;
}

codeArea.addEventListener('input', () => {
  if (currentFile) {
    files[currentFile] = codeArea.value;
    updatePreview(currentFile);
  }
});

previewFrame.addEventListener('load', () => {
  const iframeWindow = previewFrame.contentWindow;
  iframeWindow.addEventListener('click', handleIframeClick);

  // Override the window.location object in the iframe
  Object.defineProperty(iframeWindow, 'location', {
    set: function(value) {
      if (typeof value === 'string') {
        navigateTo(value);
      } else if (value && typeof value.href === 'string') {
        navigateTo(value.href);
      }
    },
    get: function() {
      return {
        href: currentFile,
        assign: function(url) {
          navigateTo(url);
        },
        replace: function(url) {
          navigateTo(url);
        }
      };
    }
  });

  // Override history methods
  iframeWindow.history.pushState = function(state, title, url) {
    navigateTo(url);
  };
  iframeWindow.history.replaceState = function(state, title, url) {
    navigateTo(url);
  };
});

function handleIframeClick(event) {
  if (event.target.tagName === 'A') {
    event.preventDefault();
    const href = event.target.getAttribute('href');
    navigateTo(href);
  } else if (event.target.tagName === 'BUTTON' || event.target.tagName === 'INPUT') {
    const clickEvent = new MouseEvent('click', {
      bubbles: true,
      cancelable: true,
      view: previewFrame.contentWindow
    });
    event.target.dispatchEvent(clickEvent);
  }
}

function navigateTo(path) {
  // Handle relative paths
  if (!path.startsWith('/') && !path.startsWith('http')) {
    const currentDir = currentFile.split('/').slice(0, -1).join('/');
    path = `${currentDir}/${path}`;
  }

  // Normalize path
  path = path.replace(//.//g, '/').replace(//[^/]+/..//g, '/');

  if (files[path]) {
    openFile(path);
  } else if (path.startsWith('http')) {
    console.log(`External URL: ${path}`);
    // Handle external URLs as needed
  } else {
    console.error(`File not found: ${path}`);
  }
}

window.addEventListener('popstate', function(event) {
  if (event.state && event.state.file) {
    openFile(event.state.file);
  } else {
    const fileName = window.location.hash.slice(1);
    if (files[fileName]) {
      openFile(fileName);
    }
  }
});

// Initialize with index.html if it exists
if (files['index.html']) {
  openFile('index.html');
}
<div class="container">
  <div class="file-explorer">
    <h3>Files</h3>
    <ul id="fileList"></ul>
    <input type="file" id="fileInput" multiple>
  </div>
  <div class="editor">
    <div class="tabs" id="tabs"></div>
    <textarea class="code-area" id="codeArea"></textarea>
  </div>
  <iframe class="preview" id="previewFrame" src="about:blank"></iframe>
</div>

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật