File size: 3,545 Bytes
dfa7ee3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!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>