Single Post |
Topic: Перезагрузка страниц |
Author |
Message |
DrShark
|
Posted: Wed Jun 13, 2007 14:01 Post subject: |
|
|
Quote: | Successful approach
Given a tag like so: <META http-equiv="refresh" content="n"/>
Code: |
var stopTimer = window.setTimeout("window.stop();",
(n-1)*1000); // in case load hasn't finished when the refresh fires
window.addEventListener("load", function(){
try { window.clearTimeout(stopTimer); } catch(ex) {}
window.stop();
}, true); |
First Attempt
Mozilla (and Firefox) have an interface called nsIRefreshURI, which defines a cancelRefreshURITimers() function. However, I believe it is impossible to access this via a Greasemonkey user script because of security features that prevent scripts operating in the context of a remote page to access the necessary local interfaces inside Mozilla.
Here is Javascript code that (should) disable autorefresh:
Code: |
var nsIInterfaceRequestor = Components.interfaces.nsIInterfaceRequestor;
var nsIWebNavigation = Components.interfaces.nsIWebNavigation;
var nsIRefreshURI = Components.interfaces.nsIRefreshURI;
var requestor = window.QueryInterface(nsIInterfaceRequestor);
var navigator = requestor.getInterface(nsIWebNavigation);
var refresher = navigator.QueryInterface(nsIRefreshURI);
refresher.cancelRefreshURITimers(); |
This fails on the 5th line:
var navigator = requestor.getInterface(nsIWebNavigation);
with a "Permission denied to create wrapper for object of class UnnamedClass" exception. A quick web search reveals that this is a security-related error -- scripts operating in the context of a remote page can not access this particular interface. If there is another way to get to the nsIRefreshURI interface, without going through nsIWebNavigation, then it may be possible to disable autorefresh. But I haven't found it yet.
It should be possible to create a full-fledged Firefox extension to do this, since extensions operate in a more privileged context and should therefore be able to access the required interfaces.
Second attempt
Even easier would be to use the magical docShell interface:
Code: |
var nsIInterfaceRequestor = Components.interfaces.nsIInterfaceRequestor;
var nsIWebNavigation = Components.interfaces.nsIWebNavigation;
var nsIRefreshURI = Components.interfaces.nsIRefreshURI;
var requestor = window.QueryInterface(nsIInterfaceRequestor);
var navigator = requestor.getInterface(nsIWebNavigation);
var docShell = navigator.QueryInterface(nsIDocShell);
docShell.allowMetaRedirects = false; |
Again, this needs to be done with a full-fledged extension; Greasemonkey user scripts do not have privileges to access the necessary interfaces. |
Как правильно настроить какой-то из этих JS в Opera 9 для *.wincmd.ru и *.totalcmd.net? |
|
|
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|