我有一个图像作为DataURL字符串.
我想以编程方式将此图像复制到ClipBoard.
我找到了两个函数,但它们都不起作用.虽然,复制文本时第一个功能很有效 - 复制("Hello!","text");
PS我有一个"clipboardWrite"权限.
第一:
function copy(str, mimetype) {
document.oncopy = function(event) {
event.clipboardData.setData(mimetype, str);
event.preventDefault();
};
document.execCommand("Copy", false, null);
}
Run Code Online (Sandbox Code Playgroud)
第二:
function copyImage(url){
var img=document.createElement('img');
img.src=url;
document.body.appendChild(img);
var r = document.createRange();
r.setStartBefore(img);
r.setEndAfter(img);
r.selectNode(img);
var sel = window.getSelection();
sel.addRange(r);
document.execCommand('Copy');
}
Run Code Online (Sandbox Code Playgroud) 当我将新标签重定向到新网址时,地址栏中的焦点仍保持在原来的位置,这非常烦人。如果用户从 Chrome 窗口中移除焦点然后再次返回,带有建议的巨大窗口会出现在地址栏下方。如何更改“newtab”的 url 以使焦点移动到页面?
chrome.browserAction.onClicked.addListener(function(tab){
var url={url:"http://example.com"};
if( tab.url.toLowerCase() == "chrome://newtab/" )
chrome.tabs.update(tab.id,url);
else
chrome.tabs.create(url);
});
Run Code Online (Sandbox Code Playgroud) 我有jQuery的代码:
$(document).on("mouseenter","a",function(e){
//...
});
Run Code Online (Sandbox Code Playgroud)
如何使用本地JavaScript(不使用jQuery)创建相同的代码?
我只需要兼容Chrome。
我通过以下代码请求许可:
chrome.permissions.request({permissions:["<all_urls>"]},function(granted){
if(granted) {
;;
}
});
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
Unchecked runtime.lastError while running permissions.request: '<all_urls>' is not a recognized permission.
Run Code Online (Sandbox Code Playgroud)
这是错误吗?
我需要将带有 get-parameters 的 url 回显到文本文件。
当我尝试:
set url=text=2
echo %url% > file.txt
Run Code Online (Sandbox Code Playgroud)
结果几乎没问题:
text=2
Run Code Online (Sandbox Code Playgroud)
但是数字 2 后面有一个空格是不需要的
如果我尝试从代码中删除该空间:
set url=text=2
echo %url%> file.txt
Run Code Online (Sandbox Code Playgroud)
但结果只是空的!
是否可以在末尾没有空格的情况下回显“text=2”?
实际代码中的PS url其实是这样的:
set url=%~1
Run Code Online (Sandbox Code Playgroud)