vanilla - 刷新页面时更改base64编码的图像

时间:2017-07-21 07:03:29

标签: javascript base64



<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="apple-touch-icon" href="apple-touch-icon.png">

        <style type="text/css">

            /* author css */
            body, html, .wrapper, .container {
                width: 100%;
                height: 100%;
            }
            .container {
                max-width: 100%;
                height: 100%;
                margin: 0 auto;
                position: relative;
            }

            .logo {
                width: 50%;
                display: block;
                margin: 0 auto;
                text-align: center;
                padding-top: 160px;
            }

            .error-page {
                background-position: center center;
                background-repeat: no-repeat;
                background-size: 100%;
                height: 100%; 
            }
            @media (max-width: 1024px) {
                .error-page {
                    background-position: center -100px;
                }
            }

            .en_lang .error-page {
                background-image: url();
            }
            @media (min-width: 1024px) {
               .en_lang .error-page {
                    background-image: url();
                }
            }

            .de_lang .error-page {
                background-image: url();
            }
            @media (min-width: 1024px) {
               .de_lang .error-page {
                    background-image: url();
                }
            }

            .fr_lang .error-page {
                background-image: url();
            }
            @media (min-width: 1024px) {
               .fr_lang .error-page {
                    background-image: url();
                }
            }

            .es_lang .error-page {
                background-image: url();
            }
            @media (min-width: 1024px) {
               .es_lang .error-page {
                    background-image: url();
                }
            }

            .it_lang .error-page {
                background-image: url();
            }
            @media (min-width: 1024px) {
               .it_lang .error-page {
                    background-image: url();
                }
            }

            .br_lang .error-page {
                background-image: url();
            }
            @media (min-width: 1024px) {
               .br_lang .error-page {
                    background-image: url();
                }
            }
        </style>
    </head>
    <body class="en_lang">
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <div class="wrapper">
            <div class="container">
                <div class="error-page">&nbsp;</div>
            </div>
        </div>
    </body>
</html>
&#13;
&#13;
&#13;

我尝试制作一个简单的脚本,以便在刷新页面时以随机方式自动更改背景图像。

我必须指明一些事情:

  1. 图像编码为base64;
  2. 我不能使用外部资产
  3. 我必须使用vanilla javascript
  4. 你可以看看de.istefan.ro(成人内容)

    现在我只使用此代码将正确的图像分配给正确的用户语言选择:

    (function() {
        // check url and add the language class to the body tag
        var className = window.location.host.split('.')[0];
        className = (className =='istefan')? 'en_lang' : className+'_lang';
    
        document.getElementsByTagName('body')[0].setAttribute('class', className );
    })();
    

    谢谢你们。

0 个答案:

没有答案