[英]How to choose a specific window based on its title
I want to choose a specific window, and perform operations on that window- I will pass that window as a parameter to another function which does the work... 我想选择一个特定的窗口,然后对该窗口执行操作-我会将那个窗口作为参数传递给另一个起作用的函数...
I know beforehand, that the title of the windows is (for example) "XYZ" 我事先知道,窗口的标题是(例如)“ XYZ”
How do I select the window in browser with that title? 如何在浏览器中选择带有该标题的窗口?
I found that in javascript there are ways to assign a title to a window, but I couldnt find a way to search for and find the window which has a specific title. 我发现在javascript中,有一些方法可以为窗口分配标题,但是我无法找到一种方法来搜索并找到具有特定标题的窗口。
You cannot select other windows, unless you've already got a reference to it. 您不能选择其他窗口,除非您已经对其进行了引用。
There are two methods to get a reference: 有两种方法可以获取参考:
window.opener
property holds a reference to the window which opened the current one. window.opener
属性保存对打开当前窗口的窗口的引用。 window.open()
also offers a reference. window.open()
的返回值也提供了参考。 Each reference to another window will be a window
object. 对另一个窗口的每个引用将是一个
window
对象。 window.document.title
can be used to read the value of the title. window.document.title
可用于读取标题的值。 (where window
is the reference to the other window). (其中
window
是对另一个窗口的引用)。
Cross-domain restrictions will prevent other windows from being read, though. 但是,跨域限制将阻止读取其他窗口。
See this answer to read the document/window object of embedded frames. 请参阅此答案以阅读嵌入式框架的文档/窗口对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.