Firefox扩展开发:获取新标签的URL [英] Firefox extension development : Get URL of new tab
问题描述
//浏览器对象指向使用
/ /'TabOpen'Event
var browser = gBrowser.getBrowserForTab(event.target);
//从哪里可以得到这个新标签的网址?另外,如何获得
//这个新标签的标题
..
让我们一起来看看。首先在google搜索getBrowserForTab来查看它返回的是什么样的对象。您将看到一个页面,其中包含第一个匹配的示例,以及参考页面作为第二击。后者是我们正在寻找的。它说:
浏览器的指定标签元素。
请点击 同样,你会发现它有一个 currentURI 属性,它返回当前加载的URL。返回的对象是一个 up: 您也可以获取 希望这会有所帮助,下次您提出问题时,您将自己尝试执行此操作(如果找不到文档或难以理解,请指出遇到的具体问题)。 Can anybody tell me how to get the URl of the next tab on firefox ? I am using this now : Thanks in advance.. Let's try to figure this out together. First search google for "getBrowserForTab" to see what kind of object it returns. You'll see a page with examples as the first hit, and the reference page as the second hit. The latter is what we're looking for. It says: [getBrowserForTab( tab )] Returns a browser for the specified tab element. Follow the link for browser to see what properties and methods this object has. You'll see it has a contentTitle property ("This read-only property contains the title of the document object in the browser."), which answers the second part of your question. Similarly you see it has a currentURI property which returns "the currently loaded URL". The returned object is an So to sum up: You could also just get the Hope this helps and you'll try to do this yourself next time you ask a question (and if you can't find the documentation or have trouble understanding it, indicate what specific problems you encountered). 这篇关于Firefox扩展开发:获取新标签的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
nsIURI
,以获得它的字符串表示形式,您需要使用 currentURI.spec
nsIURI文档。
var title = browser.contentTitle; //返回当前加载页面的标题
var url = browser.currentURI.spec; //将当前加载的URL作为字符串返回
通过
并使用您在常规网页中使用的API获取标题/ URL(以及其他内容)。 browser.contentWindow
/ <$ c $ / 文档
c> browser.contentDocument
//The browser object points to the new tab which I capture using the
//'TabOpen' Event
var browser = gBrowser.getBrowserForTab(event.target);
//From where can I get the URL of this new tab ? Also, how to I get
//the Title of this new Tab
nsIURI
, to get its string representation you need to use currentURI.spec
, as described in the nsIURI documentation.var title = browser.contentTitle; // returns the title of the currently loaded page
var url = browser.currentURI.spec; // returns the currently loaded URL as string
window
/document
objects of the content page via browser.contentWindow
/browser.contentDocument
and get the title/URL (and other things) using the APIs you would use in a regular web page.