美文网首页
js创建 网页-桌面快捷方式

js创建 网页-桌面快捷方式

作者: yichen_china | 来源:发表于2024-09-22 14:50 被阅读0次
    <!DOCTYPE html>
    <html lang="zh">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <title>js创建 网页-桌面快捷方式</title>
            <style>
                #downdiv{
                    position:fixed;
                    top:30px;
                    right:30px;
                    z-index:9999999;
                }
                #downdiv input{
                display: block;
                width: 100%;
                }
                #down_btn {
                font-size:50px;
                color:lawngreen;
                }
            </style>
        </head>
        <body>
    

    js创建 网页-桌面快捷方式

            <script type="text/javascript">
                //   javascript:
                (function() {
                   var content=`[{000214A0-0000-0000-C000-000000000046}] \n
    Prop3=19,11  \n
    [InternetShortcut]  \n
    IDList= \n
    URL=${location.href} \n
    IconFile=${location.protocol}//${location.hostname}/favicon.ico \n
    IconIndex=1 \n
    `;
     
                    
                    var downdiv = document.createElement("div");
                    downdiv.id="downdiv";
                    downdiv.innerHTML=`
                    <style>
                        #downdiv{
                            position:fixed;
                            top:30px;
                            right:30px;
                            z-index:9999999;
                        }
                        #downdiv input{
                        display: block;
                        width: 100%;
                        }
                        #down_btn {
                        font-size:50px;
                        color:lawngreen;
                        }
                    </style>
                    名称:<input type="text" id="sitetitle" value="__${document.title}__url" />
                    网址:<input type="text" id="siteurl" value="${location.href}" />
                    `;
                    
                    var down_btn = document.createElement("button");
                    down_btn.innerText = "下载 URL桌面快捷方式";
                    down_btn.title = "注意查看,下载文件";
                    down_btn.id = "down_btn";
                    
                    downdiv.appendChild(down_btn);
                    document.body.appendChild(downdiv);
                    
                    var eledowndiv = document.querySelector("#downdiv");
                    var eleButton = document.querySelector("#down_btn");
                    var funDownload = function(content, filename) {
                        var eleLink = document.createElement("a");
                        eleLink.download = filename;
                        eleLink.style.display = "none";
                        var blob = new Blob([content]);
                        eleLink.href = URL.createObjectURL(blob);
                        document.body.appendChild(eleLink);
                        eleLink.click();
                        document.body.removeChild(eleLink)
                    };
                    if ("download" in document.createElement("a")) {
                        eleButton.addEventListener("click", function() {
                            var sitename =document.querySelector('#sitetitle').value||document.title;
                            document.body.removeChild(eledowndiv);
                            
                            funDownload(content,  sitename + ".url")
                        })
                    } else {
                        eleButton.onclick = function() {
                            alert("浏览器不支持")
                        }
                    }
                })();
            </script>
            
            <script type="text/javascript-------------书签工具  添加书签,地址栏 copy 如下代码  --------------">
                javascript:(function(){var content=`[{000214A0-0000-0000-C000-000000000046}]\nProp3=19,11\n[InternetShortcut]\nIDList=\nURL=${location.href}\nIconFile=${location.protocol}//${location.hostname}/favicon.ico\nIconIndex=1\n`;var downdiv=document.createElement("div");downdiv.id="downdiv";downdiv.innerHTML=`<style>#downdiv{position:fixed;top:30px;right:30px;z-index:9999999}#downdiv input{display:block;width:100%}#down_btn{font-size:50px;color:lawngreen}</style>名称:<input type="text"id="sitetitle"value="__${document.title}__url"/>网址:<input type="text"id="siteurl"value="${location.href}"/>`;var down_btn=document.createElement("button");down_btn.innerText="下载 URL桌面快捷方式";down_btn.title="注意查看,下载文件";down_btn.id="down_btn";downdiv.appendChild(down_btn);document.body.appendChild(downdiv);var eledowndiv=document.querySelector("#downdiv");var eleButton=document.querySelector("#down_btn");var funDownload=function(content,filename){var eleLink=document.createElement("a");eleLink.download=filename;eleLink.style.display="none";var blob=new Blob([content]);eleLink.href=URL.createObjectURL(blob);document.body.appendChild(eleLink);eleLink.click();document.body.removeChild(eleLink)};if("download"in document.createElement("a")){eleButton.addEventListener("click",function(){var sitename=document.querySelector('#sitetitle').value||document.title;document.body.removeChild(eledowndiv);funDownload(content,sitename+".url")})}else{eleButton.onclick=function(){alert("浏览器不支持")}}})();
            </script>
     
        </body>
    </html>
    

    相关文章

      网友评论

          本文标题:js创建 网页-桌面快捷方式

          本文链接:https://www.haomeiwen.com/subject/tbtxrjtx.html