Мой исходный код работает; Он считывает пары URL в поисках OK. Это то, что я пытаюсь сделать с текущим кодом. Там нет ошибок CORS. Но код пропускает поиск и не показывает ошибок.
Код: Выделить всё
const lookuptable = {
"http://example.com/redirect-test/":"http://example2.com/redirect-test2/",
};
let CurrentUrlwindow = window.location.href;
const getRedirectUrl = () => {
let newUrl = lookuptable[window.location.href];
if (!newUrl) {
newUrl = "https://example2.com" + window.location.pathname;
}
return newUrl;
};
document.addEventListener("DOMContentLoaded", (event) => {
const url = getRedirectUrl();
const linkText = "Click here to go to the new site";
const element = document.getElementById("link");
element.title = "Click here to go to the new site";
const anchor = document.createElement('a');
anchor.setAttribute('href', url);
anchor.textContent = linkText;
document.getElementById('link').appendChild(anchor);
});
Код: Выделить всё
import {lookuptable} from 'https://abcd.pages.dev/lookuptable.js';
// const lookuptable = ??
let CurrentUrlwindow = window.location.href;
const getRedirectUrl = () => {
let newUrl = lookuptable[window.location.href];
if (!newUrl) {
newUrl = "https://example2.com" + window.location.pathname;
}
return newUrl;
};
document.addEventListener("DOMContentLoaded", (event) => {
const url = getRedirectUrl();
const linkText = "Click here to go to the new site";
const element = document.getElementById("link");
element.title = "Click here to go to the new site";
const anchor = document.createElement('a');
anchor.setAttribute('href', url);
anchor.textContent = linkText;
document.getElementById('link').appendChild(anchor);
});
Код: Выделить всё
export const lookuptable = {
"http://example.com/redirect-test/":"http://example2.com/redirect-test2/",
// more
};
< /code>
html < /p>
Подробнее здесь: https://stackoverflow.com/questions/796 ... javascript
Мобильная версия