【问题标题】:Custom Chrome URL suggestions自定义 Chrome 网址建议
【发布时间】:2012-11-16 06:23:35
【问题描述】:

Chrome 的一个巧妙之处在于,如果您在地址栏上输入一个词,它会提示可能是哪些相关 URL。例如,如果我输入“New York”,它会建议 nytimes.com

可以开发提供定制建议的扩展程序吗?例如,如果我有一个内部公司网站,比如说 foo,它托管具有数字 ID 的文档 - 例如 http://domain.com/123http://domain.com/234。当有人在浏览器地址栏输入“123”时,我希望http://domain.com/123 显示为建议(即使之前从未访问过)。

这样的事情可能吗?如果是这样,我会喜欢一些指针(我从未开发过 Chrome 扩展,但如果可能的话,我可以查找并实现它)。

谢谢! 拉杰

【问题讨论】:

    标签: google-chrome browser google-chrome-extension


    【解决方案1】:

    是的,可以通过 Omnibox,https://developer.chrome.com/extensions/omnibox.html 我在这里写了一个示例实现:

    Manifest File:
    
    {
    
     "name": "Omnibox Demo",
    
      "description" : "This is used for demonstrating Omnibox",
    
      "version": "1",
    
      "background": {
    
        "scripts": ["background.js"]
    
      },
    
      "omnibox": {
     "keyword" : "demo" 
    },
    
      "manifest_version": 2
    
    }
    
    JS File:
    
    chrome.omnibox.setDefaultSuggestion({"description":"Search %s in Dev Source Code"});
    
    chrome.omnibox.onInputStarted.addListener(function() {
    
        console.log("Input Started");
    
    
    });
    
    chrome.omnibox.onInputCancelled.addListener(function() {
    
        console.log("Input Cancelled");
    
    });
    
    chrome.omnibox.onInputEntered.addListener(function (text) {
        console.log("Input Entered is " + text);
    });
    
    chrome.omnibox.onInputChanged.addListener(
    
      function(text, suggest) {
    
        console.log('inputChanged: ' + text);
    
        suggest([
    
          {content: text + " one", description: "the first one"},
          {content: text + " number two", description: "the second entry"}
        ]);
      });
    

    【讨论】:

    • 谢谢。我会调查此事!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    • 2019-09-08
    相关资源
    最近更新 更多