戻る

document.referrer
前回(リファラー)のURLを取得

referrerプロパティは、前回ページのURLを文字列で返します。
存在しないケース
ページを直接開いた場合や、ブックマークからアクセスした場合は、
リファラー情報は空の文字列 "" になります。






[サンプル]
copy
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') ?? '';

});

const referrerPath = document.referrer;
前回(リファラー)のURLを取得します。
リファラーページの完全なURL文字列を返します。
前回のURLから、このページを開き、このページのボタンを選択した場合は
前回のURLを取得した結果を返します。


戻る


著作権情報
ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。
ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、
または公開したりすることはできません。
当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、
その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について
一切の責任を負わないものとします。