简体   繁体   English

如何使用 php 或 javascript 在所有浏览器中获取当前打开的选项卡的 url?

[英]How to get the url of currently opened tabs in all browsers with php or javascript?

If anyone can guide a bit or have little knowledge how to make it possible, please let me know.如果有人可以指导一下或对如何使其成为可能知之甚少,请告诉我。

Thanks谢谢

You can't, this information is just not available via any standard interface (except for a window you already have a reference to).您不能,此信息无法通过任何标准接口获得(您已经参考过的 window 除外)。 You can see why.你可以看到为什么。 You wouldn't want the site owner for one of your tabs to be able to know what all your other tabs were showing, that would be a massive invasion of your privacy.您不希望您的一个标签的网站所有者能够知道您所有其他标签的显示内容,这将是对您隐私的大规模侵犯。

For windows you already have a reference to, you can get the URL of whatever that window is showing ( window.location.href ), and possibly that of its parent window ( window.parent.location.href ), top-level ( window.top.location.href ), and subordinate frames ( window.frames[n].location.href — I think). For windows you already have a reference to, you can get the URL of whatever that window is showing ( window.location.href ), and possibly that of its parent window ( window.parent.location.href ), top-level ( window.top.location.href )和从属框架( window.frames[n].location.href - 我认为)。 But that's not going to get you the tabs you asked for.但这不会让你得到你要求的标签。

This information is likely available via the extension mechanism of various browsers (Firefox add-ins, Chrome Extensions, etc.), but that would be only for a browser extension, which requires an explicit install from the user, and (currently) requires writing one for each browser vendor, where not all vendors offer an extension mechanism.此信息可能通过各种浏览器的扩展机制(Firefox 插件、Chrome 扩展等)获得,但这仅适用于浏览器扩展,需要用户显式安装,并且(当前)需要编写每个浏览器供应商都有一个,并非所有供应商都提供扩展机制。

Separately: This information is certainly not sent server-side (you tagged your question php ).另外:此信息肯定不会在服务器端发送(您标记了您的问题php )。

if you are expecting to do it from a web page, then you cannot get that through any language executed on Serverside or Client Side.如果您希望从 web 页面执行此操作,那么您无法通过在服务器端或客户端执行的任何语言来实现。

If you asked in context for Firefox Addons, this might help::如果您在上下文中询问 Firefox 插件,这可能会有所帮助:

var tabs = require("tabs");
for each (var tab in tabs)
  console.log(tab.url);

But this works only for Firefox Addons, not normal javascript.但这仅适用于 Firefox 插件,不适用于正常的 javascript。

Reference https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/tabs.html参考https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/tabs.html

Hope this helps.希望这可以帮助。

Actually there is a way, just bookmark all tabs and then drag the bookmark somewhere, for instance to a html form, and then you can use for instance javascript to read it from there.实际上有一种方法,只需为所有选项卡添加书签,然后将书签拖到某处,例如 html 表单,然后您可以使用例如 javascript 从那里读取它。 I don't know about other browsers yet, but in firefox you get the bookmark name, followed by all the urls, everything separated by newlines, no trailing newline at the end.我还不知道其他浏览器,但是在 firefox 中,您会获得书签名称,然后是所有 url,所有内容都由换行符分隔,最后没有尾随换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM