使用Chrome的历史记录API无法删除网址 [英] Cannot delete URLs with Chrome's history API

查看:151
本文介绍了使用Chrome的历史记录API无法删除网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Chrome浏览器的历史记录API来制作Chrome扩展程序,以从我的历史记录中移除某些网址,一>。以下是目前的代码:

  document.addEventListener('DOMContentLoaded',function(){
var form = document.getElementById('form'),
query = document.getElementById('query')
form.onsubmit = function(e){
e.preventDefault()
/ / alert(chrome.history)// [object Object]
// alert(chrome.history.deleteUrl)// function(){[native code]}
// alert(query.value) //任何我输入
chrome.history.deleteUrl(query.value)
}
query.focus()
})

form 是我的弹出窗体, query <

您可以从三个警报 s,变量很好。但是,代码实际上并未从历史记录中移除网址。当我检查( chrome:// history / )时,网址仍然存在。



这是我的 manifest.json ,如果那么重要:

  {
manifest_version:2,
name:UnVizit,
description:将链接标记为\未访问过\\,
version: 0.1.0,
permissions:[
history
],
browser_action:{
default_icon:icon.png ,
default_popup:popup.html
}
}

我使用Chrome的版本 28.0.1500.95(官方版本213514)m

解决方案

您不应该将字符串传递给 chrome.history.deleteUrl 方法,但是包含关键url的对象。如果您检查弹出窗口,您将看到以下错误:


错误:窗体history.deleteUrl(string)的调用与定义history.deleteUrl(对象细节,可选函数回调)不匹配


总之,更改

  chrome.history.deleteUrl(query.value)

chrome.history.deleteUrl({url:query.value});


I am making a Chrome extension to remove certain URLs from my history, using Chrome's history API. Here is the code so far:

document.addEventListener('DOMContentLoaded', function() {
    var form = document.getElementById('form'),
        query = document.getElementById('query')
    form.onsubmit = function(e) {
        e.preventDefault()
        // alert(chrome.history)            // [object Object]
        // alert(chrome.history.deleteUrl)  // function () { [native code] }
        // alert(query.value)               // whatever I typed
        chrome.history.deleteUrl(query.value)
    }
    query.focus()
})

(form is the form in my popup, and query is the text box in which you can type.)

As you can see from the three alerts, the variables are fine. However, the code isn't actually removing the URL from the history. When I check (in chrome://history/), the URLs are still there.

Here is my manifest.json, if that matters:

{
    "manifest_version": 2,
    "name": "UnVizit",
    "description": "Mark a link as \"not visited\" easily",
    "version": "0.1.0",
    "permissions": [
        "history"
    ],
    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    }
}

I am using version 28.0.1500.95 (Official Build 213514) m of Chrome.

解决方案

You should not pass a string to the chrome.history.deleteUrl method, but an object with key url. If you inspect your popup, you would see the following error:

Error: Invocation of form history.deleteUrl(string) doesn't match definition history.deleteUrl(object details, optional function callback)

In summary, change

chrome.history.deleteUrl(query.value)

to

chrome.history.deleteUrl({ url: query.value });

这篇关于使用Chrome的历史记录API无法删除网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆