I want to reload a page so that it does not cause the effects of a full-page refresh, like displaying "Loading..." on the page's tab.
Here's the code I have so far. My theory was that I could overwrite the body
section with a <frame>
-wrapped version of the updated site, gotten via GM_xmlhttpRequest
.
reloader.js
setInterval(reload, 10000);
function reload() {
GM_xmlhttpRequest({method: 'GET',
url: location.href,
onload: function(responseDetails) {
document.body.innerHTML =
'<frame>\n'
+ responseDetails.responseText
+ '</frame>\n';
}});
}
When testing with Firebug on stackoverflow.com, I found that this script updates the body
as if I had performed a full-page refresh, without the side effects. Yay! Mysteriously, the <frame>
tags are nowhere to be found.
Questions
What I have right now does a good job of reloading the page, but I have two questions:
- How do I stay logged in after a reload? Specifically, what do I need to do to keep me logged in to Stack Overflow?
- Can someone explain why my script works? Why are there no
<frame>
tags within thebody
?
Updates
I've incorporated elements from Cleiton, Havenard, and Henrik's answers so far. I tried sending cookies via the header: { 'Cookie': document.cookie }
entry in the data sent through GM_xmlhttpRequest
. This sent some, but not all of the cookies. It turns out that if I turn on third party cookies in the Firefox then I'll get the necessary extra cookies (.ASPXAUTH
, ASP.NET_SessionId
, and user
), but this is a bad idea.