【问题标题】:Bookmarklet to briefly flash a message用于短暂闪烁消息的书签
【发布时间】:2018-04-12 22:36:23
【问题描述】:

尝试开发一个书签来复制网页上特定字段的内容,然后短暂闪烁确认消息。已经让这两个部分分别工作。无法弄清楚如何将它们组合起来以便能够将该代码放入 Bookmarklet 的 URL 字段中。

javascript: (function(){var copyText = document.getElementById("mergeFields-input-text");copyText.select();document.execCommand("Copy"); 
function tempAlert(msg,duration)
{
     var el = document.createElement("div");
     el.setAttribute("style","position:absolute;top:5%;left:20%;background-color:white;");
     el.innerHTML = msg;
     setTimeout(function(){
      el.parentNode.removeChild(el);
     },duration);
     document.body.appendChild(el);
}

var d = document.getElementById('mergeFields-input-text');
d.onclick = function(){ tempAlert("Copied",5000); })();

【问题讨论】:

    标签: javascript html dom browser bookmarklet


    【解决方案1】:

    无需添加“onclick”事件。试试这个小书签:

    javascript:(function() {
        var copyText = document.getElementById("mergeFields-input-text");
        copyText.select();
        document.execCommand("Copy");
    
        tempAlert("Copied", 5000);
        function tempAlert(msg, duration) {
            var el = document.createElement("div");
            el.setAttribute("style","position:absolute;top:5%;left:20%;background-color:white;");
            el.innerHTML = msg;
            document.body.appendChild(el);
    
            setTimeout(function(){
                    el.parentNode.removeChild(el);
                }, duration
            );
        }
    })();
    

    【讨论】:

    • 太棒了。顺便说一句,这是为了补偿 DocuSign 实施的更改,当您最初发送信封时,它会用文件名(唯一)填充主题行,但是当您添加模板时,它会用模板的主题(通用)替换主题。此书签简化了在添加模板之前复制唯一主题的过程。我需要将其调整为我的粘贴书签,这样它也会在书签本身下方给出一个简短的确认。
    • 谢谢!复制作品。我正在尝试采用您的解决方案来粘贴单独的书签,其他一切都保持不变。这是我到目前为止所拥有的,但它不起作用:
    • 尝试采用您的解决方案来粘贴单独的书签,其他一切都保持不变。但它不起作用: javascript:(function() {var pasteText = document.getElementById("mergeFields-input-text"); .select(); document.execCommand("Paste"); tempAlert("PASTED SUBJECT", 500); function tempAlert(msg, duration) { var el = document.createElement("div"); el.setAttribute("style","position:absolute;top:2%;left:35%;background-color: green;"); el.innerHTML = msg; document.body.appendChild(el); setTimeout(function(){ el.parentNode.removeChild(el); }, 持续时间);}})();
    • 网页内容的“粘贴”命令已禁用。查看详情here
    • 以下脚本可以正常粘贴。只有当我尝试采用上述从复制到粘贴的解决方案时,什么都没有发生... javascript: (function(){var pasteText = document.getElementById("mergeFields-input-text").select();document.execCommand ("粘贴"); })();
    【解决方案2】:

    上述来自 Shugar 的代码回答了我的复制问题,下面的这段代码也来自他,除了粘贴之外,其他代码相同:

    javascript:(function() {
        var pasteText = document.getElementById("mergeFields-input-text").select();
        document.execCommand("Paste");
     
     
        tempAlert("PASTED SUBJECT", 500);
        function tempAlert(msg, duration) {
            var el = document.createElement("div");
            el.setAttribute("style","position:absolute;top:2%;left:45%;background-color:yellow;");
            el.innerHTML = msg;
            document.body.appendChild(el);
     
            setTimeout(function(){
                    el.parentNode.removeChild(el);
                }, duration
            );
        }
    })();

    【讨论】:

      猜你喜欢
      • 2015-08-03
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多