简体   繁体   English

我如何确定何时加载了用滑脂猴子打开的标签?

[英]How do I find out when a tab I've opened with greasemonkey is loaded?

I'm writing a greasemonkey script to go through a list of links and open them in a new tab (reusing the same new tab for all of them), but I can't figure out how to wait until the page has loaded to load the next link... any eventListener I try to add to the new tab gives me a permission denied error... how do I check whether the new tab is fully loaded (or at least loaded enough that the server would have processed the request) or not? 我正在编写一个acobsmonkey脚本来浏览链接列表,并在新选项卡中打开它们(对所有重复使用相同的新选项卡),但是我不知道如何等待页面加载完成下一个链接...我尝试添加到新选项卡的任何eventListener都给我一个权限被拒绝的错误...我如何检查新选项卡是否已完全加载(或至少加载得足以使服务器处理请求) ) 或不? I tried unsafeWindow but also got a denied error with that (I may not fully understand the use though...) 我尝试了unsafeWindow,但是却遇到了一个被拒绝的错误(尽管我可能不完全了解其用法...)

As an example... this is ONE of the multiple things I've tried... 举例来说...这是我尝试过的多种方法之一...

mywin.addEventListener(DOMContentLoaded, false);

And here's one more (I don't remember what else I tried since I deleted them when they didn't work)........ 还有一个(我不记得我尝试了什么,因为当它们不起作用时我删除了它们)........

mywin.unsafeWindow.setTimeout(1000);

I'm not sure why I was trying to set the timeout on 'mywin' so I'm going to try setting it on the main window, but even if that works I'd still like to know the proper way of checking the status of the new tab. 我不确定为什么要尝试在“ mywin”上设置超时,因此我将尝试在主窗口上设置超时,但是即使该方法可行,我仍然想知道检查状态的正确方法新标签的

Thanks!!! 谢谢!!!

Edit: I did manage to get a setTimeout to work, but it's not the best way since too low a setting means they don't get loaded an a slow connection, and too high a setting means a major delay with a faster connection. 编辑:我确实设法使setTimeout正常工作,但这不是最好的方法,因为设置太低意味着它们不会加载较慢的连接,而设置太高则意味着使用较快的连接会严重延迟。

So I'm still looking for a better way! 所以我还在寻找更好的方法!

edit: It shouldn't (but might) fall under cross-site/cross-domain scripting as all links are on the same site... 编辑:它不应该 (但可能)属于跨站点/跨域脚本,因为所有链接都在同一站点上...

starting with 
http://www.aywas.com/message/notices/

the links being opened are like these
http://www.aywas.com/message/notices/9767066/
http://www.aywas.com/message/notices/9765913/
http://www.aywas.com/message/notices/9765644/

Edit: Would GM_xmlhttpRequest or http-on-examine-response possibly work for this? 编辑:GM_xmlhttpRequest或http-on-examine-response可能对此起作用吗? If so, how would I do that? 如果是这样,我该怎么做?

I found a way around the problem... oddly enough, I couldn't do it when using GM_openInTab to create the window, but using 我找到了解决问题的方法...奇怪的是,使用GM_openInTab创建窗口时我做不到,但是使用

mywin2=window.open("http://www.aywas.com/message/notices/9801049/", "my_win2");

allowed me to use the following code to detect the load and close the tab only after it was loaded enough for my purposes! 允许我使用以下代码来检测负载并仅在为我的目的加载足够的选项卡后关闭选项卡! (Although the 'window title' bit of that code above didn't seem to do anything...) (尽管上面的代码的“窗口标题”似乎没有任何作用...)

mywin2.addEventListener('load', function() {
  mywin2.close()
}, false);

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

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