soiz1's picture
Create yt
dfa7ee3 verified
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URLパラメーター版HTMLビューアー</title>
<style>
body { font-family: Arial, sans-serif; }
</style>
</head>
<body>
<h1>URLパラメーター版HTMLビューアー</h1>
<p>パラメーター例:?mode=html&open=about-blank&content=&lt;h1&gt;こんにちは&lt;/h1&gt;</p>
<p>パラメーター例:?mode=url&open=blob&content=https://example.com</p>
<script>
function getQueryParams() {
const params = new URLSearchParams(window.location.search);
return {
mode: params.get('mode'),
open: params.get('open'),
content: params.get('content')
};
}
function displayContent() {
const { mode, open, content } = getQueryParams();
if (!mode || !open || !content) {
document.body.innerHTML += '<p style="color: red;">パラメーターが不足しています。</p>';
return;
}
if (mode === 'html') {
displayHTML(content, open);
} else if (mode === 'url') {
displayURL(content, open);
} else {
document.body.innerHTML += '<p style="color: red;">無効なモード指定です。</p>';
}
}
function displayHTML(html, target) {
if (target === 'blob') {
const blob = new Blob([html], { type: 'text/html' });
const url = URL.createObjectURL(blob);
window.open(url);
} else if (target === 'about-blank') {
const newWindow = window.open('about:blank');
if (newWindow) {
newWindow.document.write(html);
newWindow.document.close();
} else {
alert('ポップアップがブロックされている可能性があります。');
}
} else {
alert('無効な表示方法です。');
}
navigateToRoot();
}
function displayURL(url, target) {
const iframeHtml = `<!DOCTYPE html><html lang="ja"><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>iframe表示</title><style>html,body{margin:0;padding:0;overflow:hidden;width:100vw;height:100vh}</style><iframe src="${url}" style="width:100vw;height:100vh;border:none;display:block;margin:0;padding:0"></iframe></html>`;
if (target === 'blob') {
const blob = new Blob([iframeHtml], { type: 'text/html' });
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl);
} else if (target === 'about-blank') {
const newWindow = window.open('about:blank');
if (newWindow) {
newWindow.document.write(iframeHtml);
newWindow.document.close();
} else {
alert('ポップアップがブロックされている可能性があります。');
}
} else {
alert('無効な表示方法です。');
}
navigateToRoot();
}
function navigateToRoot() {
window.location.href = '/';
}
displayContent();
</script>
</body>
</html>