简体   繁体   English

如何将此屏幕截图保存在本地驱动器中而不弹出任何窗口?

[英]how to save this screenshot in local drive without any pop up?

I want to save this screenshot in local drive without showing a popup to download.我想将此屏幕截图保存在本地驱动器中而不显示要下载的弹出窗口。

    (function() {
        'use strict';
        $("body").prepend ( `
    <button id="btCapture">SCREENSHOT</button>
    <input type="submit" value="Take Screenshot Of Div" onclick="capture();" />
    <form method="POST" enctype="multipart/form-data" action="save.php" id="myForm">
    <input type="hidden" name="img_val" id="img_val" value="" />
    </form>
    <div></div>`);

    document.getElementById("btCapture").onclick = function() { generate();};
        (function (exports) {
            function urlsToAbsolute(nodeList) {
                if (!nodeList.length) {
                    return [];
                }
                var attrName = 'href';
                if (nodeList[0].prototype === HTMLImageElement.prototype || nodeList[0].protottype === HTMLScriptElement.prototype) {
                    attrName = 'src';
                }
                nodeList = [].map.call(nodeList, function (el, i) {
                    var attr = el.getAttribute(attrName);
                    if (!attr) {
                        return;
                    }
                    var absURL = /^(https?|data):/i.test(attr);
                    if (absURL) {
                        return el;
                    } else {
                        return el;
                    }
                });
                return nodeList;
            }

            function screenshotPage() {
                urlsToAbsolute(document.images);
                urlsToAbsolute(document.querySelectorAll("link[rel='stylesheet']"));
                var screenshot = document.documentElement.cloneNode(true);
                var b = document.createElement('base');
                b.href = document.location.protocol + '//' + location.host;
                var head = screenshot.querySelector('head');
                head.insertBefore(b, head.firstChild);
                screenshot.style.pointerEvents = 'none';
                screenshot.style.overflow = 'hidden';
                screenshot.style.webkitUserSelect = 'none';
                screenshot.style.mozUserSelect = 'none';
                screenshot.style.msUserSelect = 'none';
                screenshot.style.oUserSelect = 'none';
                screenshot.style.userSelect = 'none';
                screenshot.dataset.scrollX = window.scrollX;
                screenshot.dataset.scrollY = window.scrollY;
                var script = document.createElement('script');
                script.textContent = '(' + addOnPageLoad_.toString() + ')();';
                screenshot.querySelector('body').appendChild(script);
                var blob = new Blob([screenshot.outerHTML], {
                    type: 'text/html'
                });
                return blob;
            }

            function addOnPageLoad_() {
                window.addEventListener('DOMContentLoaded', function (e) {
                    var scrollX = document.documentElement.dataset.scrollX || 0;
                    var scrollY = document.documentElement.dataset.scrollY || 0;
                    window.scrollTo(scrollX, scrollY);
                });
            }

            function generate() {
                window.URL = window.URL || window.webkitURL;
                window.open(window.URL.createObjectURL(screenshotPage()));
            }
            exports.screenshotPage = screenshotPage;
            exports.generate = generate;
        })(window);
    })

;

You can't.你不能。 Allowing web pages to write files to arbitrary paths on the end-user's machine would be a massive hole for malware to exploit.允许网页将文件写入最终用户机器上的任意路径将是恶意软件利用的一个巨大漏洞。 The user must be involved.用户必须参与。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在本地驱动器中保存网页屏幕截图 - How to save web page screenshot in local drive 弹出窗口保存在本地存储中 - Pop-up windows save in local storage 如何将签名保存到本地驱动器 - How to save the signature to local drive 如何设置Google云端硬盘客户端ID以在没有本地服务器的情况下进行访问? - How to set up a Google Drive Client ID for access without a local server? 如何在不单击的情况下将 Netsuite 文件柜中的 PDF 文件下载到本地驱动器? - How to Download PDF files from Netsuite File Cabinet to Local drive without any click? 如何在不单击任何按钮并获得用户响应的情况下显示C#代码后面带有“是”和“否”选项的弹出窗口 - How to display Pop-up with Yes and No option from C# code behind without clicking any button and taking response from user 如何弹出“保存到Excel”对话框? - How do I get the a save to excel dialog box to pop up? 如何在任何网站的选定文本之上显示弹出消息? - How to display pop up message on top of selected text in any website? 当我单击该树的任何项目时如何创建弹出窗口 - How to create a pop up when I click on any item of this tree 有什么解决方案可以处理 Selenium Web 驱动程序中窗口打印功能的“另存为 pdf”弹出窗口? - Is there any solution to deal “Save as pdf” pop up for window print function in Selenium Web driver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM