document.referrer |
前回(リファラー)のURLを取得 |
const btn = document.getElementById("btn");
btn.addEventListener("click", () =>
{
referrerURL();
});
function referrerURL()
{
const referrerPath = document.referrer;
let file = fileId(referrerPath);
let directory = directoryPath(referrerPath);
console.log("referrerPath:" + referrerPath);//referrerPath:http://localhost/test.html
console.log("file:" + file);//file:test.html
console.log("directory:" + directory);//directory:http://localhost/
console.log("path:" + directory + file);//http://localhost/test.html
}
function fileId(path)
{
return path.split('/').pop();
}
function directoryPath(path)
{
const lastSlashIndex = path.lastIndexOf('/');
return path.substring(0, lastSlashIndex + 1);
}
window.addEventListener("load", ()=>{
const path = localStorage.getItem('path') ?? '';
});
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |