I want a function that stops a page from loading if Google Plus One couldn't load in 5 seconds. In our country sometimes the HTTPS port is blocked by the telecommunications department and we don't have access to apis.google.com. It is not just slow, we realy don't have access to the HTTPS port. If this is the case I want some way of stopping the page from loading when we can't access https://apis.google.com/js/plusone.js. How can I do this?
Asked
Active
Viewed 309 times
1
-
3cannot you keep `plusone.js` on your own server? – Asif Apr 26 '12 at 20:41
-
1also, `plusone.js` makes Ajax request that browsers cannot handle in case of direct opening that html file from your own disk but will work fluently with a server, keep aware of this. – Asif Apr 26 '12 at 20:47
-
Please [don't add signatures or taglines to your posts](http://stackoverflow.com/faq#signatures). – user229044 Apr 26 '12 at 20:53
-
yeah when you put js file in your host nothing change at all.js file must comunicate to google server after all. – HiDd3N Apr 26 '12 at 21:10
2 Answers
1
Just check to see if the Plusone script loads within 5 seconds, like so:
var i=0, checkPlusone = setInterval(function() {
if (typeof gapi!='undefined') {
if (gapi.hasOwnProperty('plusone')) {
clearInterval(checkPlusone);
console.log('Plusone loaded');
}
}
if (i>5000) {
clearInterval(checkPlusone);
console.log('Plusone not loaded');
window.location = "http://www.mypage.com/no_plusone.html"; //redirect to error page
}
i=i+300;
}, 300);

adeneo
- 312,895
- 29
- 395
- 388
-
thanks for asnwer but thats not what i want.why redirect?if redirect happens then home page always redirect to home page. – HiDd3N Apr 26 '12 at 21:20
-
just copy and paste this code and plus one will work??or i have to change it somehow? – HiDd3N Apr 26 '12 at 21:28
-
In your question you write "I want a function that stops a page from loading if Google Plus One couldn't load in 5 seconds", this is it ? You can't really stop the page from loading, but good practice is to redirect to an error page instead, or do whatever you like, this checks if plusone is loaded within 5 seconds, what you do if it is/is'nt loaded is up 2 u. – adeneo Apr 26 '12 at 21:29
-
Noone said anything about making plusone work, if you don't have access to the Google API, there's not much I can do about it ? – adeneo Apr 26 '12 at 21:33
-
realy realy thanks.i thing my problem solved with one adjustment.i change redirect to stop(); but is this code usefull in any browser? – HiDd3N Apr 26 '12 at 21:35
-
ok thanks its realy work:)) ..realy realy thanks.i just put this code in end of my body..before
tag and its work like magic:D...cause my page load is completed and then if plus one wont show up stoping the process.thanks
– HiDd3N Apr 26 '12 at 21:47
0
You could load the file with ajax and use a timeout.
Ctrl+F for "timeout" on the jQuery ajax docs page, and see it in use in this SO question.

Community
- 1
- 1

HappyTimeGopher
- 1,377
- 9
- 14
-
can you write code for me i am newbie in ajax.i just want to kill the page after 5 seconds how i can i do that?? – HiDd3N Apr 26 '12 at 21:06