2012-11-16 38 views
0

有关Chrome浏览器的一个巧妙之处是,如果您在地址栏上键入一个单词,它会建议相关的URL可能是什么。例如,如果我输入“纽约”,它建议nytimes.com自定义Chrome网址建议

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

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

谢谢! 拉吉

回答

2

是的,有可能通过多功能框,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"} 
    ]); 
    }); 
+0

谢谢。我会调查这个! – ragebiswas