Opv Posted February 25, 2012 Share Posted February 25, 2012 I'm attempint to get the Facebook message page to reload once I go to the page. The URL I see in the address bar when I go to the page is http://www.facebook.com/messages/ I've tried a simple greasemonkey script and included the @include as *facebook.com/messages* and includes the following snippet: window.onload=initReload(); function initReload() { window.location.reload();} However, nothing happens when I access the message page. Is there not a way to force the page to reload as if I had pressed F5 after the page is initially loaded? (Please don't ask me why I need to do this. I have a legitimate need, even if it does sound irrational.) Link to comment Share on other sites More sharing options...
Opv Posted February 26, 2012 Author Share Posted February 26, 2012 My limited experience with Javascript tells me that what I want to achieve may not be possible, at lesat not using the methodology currently implemented, as when window.onload calls the approrpiate function to reload the page, the window.onload event is again fired, causing a infinite loop. Is there any way around this so that there is only one hard refresh after the page loads? Link to comment Share on other sites More sharing options...
Ingolme Posted February 26, 2012 Share Posted February 26, 2012 Your only problem is that you're excecuting a function instead of assigning it to the event handler.Do this instead: window.onload=initReload; You only need parenthesis when executing the function. Your script, though, is going to reload the page over and over without stopping. Link to comment Share on other sites More sharing options...
Opv Posted February 26, 2012 Author Share Posted February 26, 2012 I was going to try to combine an interval and timer and a clearInterval to avoid the ongoing loop. That may not be possible seeing that once the page reloads, the whole process would start all over again. At any rate, I tried the windows.onload=initReload; and it's still not causing the script to run on page load. The Facebook messages page is disigned some way that is requiring a manual refresh of the page before the desired script runs. That's what I was trying to get around is forcing the page to reload so that my other utility would run automatically. But, I only need that reload to occur once. Thanks.. Link to comment Share on other sites More sharing options...
Ingolme Posted February 27, 2012 Share Posted February 27, 2012 I don't see how this couldn't work for you window.onload=initReload;function initReload() { window.location.reload();} Maybe greasemonkey requires you to work with the unsafe window for that. Try this: unsafeWindow.onload=initReload;function initReload() { unsafeWindow.location.reload();} Personally, I'd use addEventListener(), I never had a problem with greasemonkey using that. window.addEventListener('load', initReload, false);function initReload() { window.location.reload();} When the page reloads, all the scripts are reset. Javascript can't tell what happened before the reload. You could use a cookie to remember that the page has already reloaded once. Link to comment Share on other sites More sharing options...
Opv Posted February 27, 2012 Author Share Posted February 27, 2012 I was thinking the GM_setValue and GM_getValue would work for my purposes? For example, I was going to create two InitReload alternatives and run the one that meets my condition with regard to the GM_getValue matched the prescribed condition, i.e., one running if the GM_getValue is NULL (and in the process storing the GM_setValue) or running the other if the GM_getValue has been stored. At any rate, the suggested unsafewindow didn't seem to help. I think it may be a Facebook issue, as the http://www.facebook.com/messages* URL is the only configuration I've ever tried where the script doesn't work as intended once the page loads. Link to comment Share on other sites More sharing options...
Opv Posted February 27, 2012 Author Share Posted February 27, 2012 Oh, and P.S., I've tried the window.addeventlistener code too but it don't seem to work either on the Facebook messages page. Link to comment Share on other sites More sharing options...
Ingolme Posted February 27, 2012 Share Posted February 27, 2012 I find that really hard to believe. Try some tests to see where it's being stopped: window.addEventListener('load',test,false);function test() { alert(1);} Link to comment Share on other sites More sharing options...
Opv Posted February 27, 2012 Author Share Posted February 27, 2012 I'll try it again but I've had absolutely no luck so far. If you are on Facebook, you can try it on your own Messages page. That seems to be the only page on which I'm having a problem with any type of onload statement. Link to comment Share on other sites More sharing options...
Opv Posted February 27, 2012 Author Share Posted February 27, 2012 No luck. I even deleted out all of my other code and only tried the suggested test. It works fine on other pages but not on the Facebook messages page. Link to comment Share on other sites More sharing options...
Ingolme Posted February 27, 2012 Share Posted February 27, 2012 I don't have a facebook account. I suppose the window is already loaded by the time the script is called. Try omitting the onload event. Link to comment Share on other sites More sharing options...
Opv Posted February 27, 2012 Author Share Posted February 27, 2012 That didn't work either. I was reading something yesterday about Facebook possibly cloaking the URL. I understood the person to be saying that the URL seen in the address bar, i.e., http://www.facebook.com/messages/, is likely not the actual URL so that may be why the Greasemonkey @include statement is not triggering the reload. There was some discussion about using Firebug to narrow down the precise page element and then performing an element load statement. I installed Firebug and I couldn't make heads or tails out of what it was telling me. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.