Java Forum / General / February 2006
Am I online?
Roedy Green - 28 Jan 2006 08:50 GMT Is there a way to detect in java or Javascript if I am online?
Or do I have to choose some tight timeout and fetch a tiny file from some fast server and see if I get it in time to decide?
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Francesco Devittori - 28 Jan 2006 09:14 GMT > Is there a way to detect in java or Javascript if I am online? > > Or do I have to choose some tight timeout and fetch a tiny file from > some fast server and see if I get it in time to decide? A ping should be faster. Otherwise maybe you could look at your ip address.
Francesco
Chris Uppal - 28 Jan 2006 12:42 GMT > Is there a way to detect in java or Javascript if I am online? What do you mean by "online" ?
A network connection is available (but may not be connected to the Net).
A network connection would be available if you attempted to use it (dial-up on demand).
It is currently possible to talk to <some specific server on the Net>.
A connection to the Net is available /and/ the user has not choosen to "work offline" (Windows specific)
A connection to the Net is available and protocol <X> is allowed in/out.
A connection to the Net is available /and/ the user is willing to incur the (financial) cost of using it.
...etc.
> Or do I have to choose some tight timeout and fetch a tiny file from > some fast server and see if I get it in time to decide? In the days (not so long ago) when I had a dial-up connection, and the connection was established on-demand, I would have been /severly/ pissed off if any program had initiated a connection (with consequent cost and delay) just to find out /whether/ a connection was available.
There are some programs that, by their nature, are so Net-bound that it is reasonable for them to assume that the Net is available by default (web-browsers, chat programs, etc). For all the others it makes more sense to let the user control whether/when/where/why it uses the Net.
-- chris
Roedy Green - 28 Jan 2006 14:08 GMT On 28 Jan 2006 12:42:23 GMT, "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly quoted someone who said :
>What do you mean by "online" ? > [quoted text clipped - 12 lines] >A connection to the Net is available /and/ the user is willing to incur >the (financial) cost of using it. I'm flexible. All I want to do is avoid javascript including Google AdSense ads when their AdServer is not available. Pretty well having an online connection to anything implies Google will be flying.
If I have the potential to dial up, but I have not done so, that does not count. I am offline browsing a mirror copy of the files.
If the user is browsing a local copy, but has a 24-7 access, I'd prefer he saw the ads. That helps pay my bills, but that is not that important.
The ads are just little hunks of text, very small a sentence or two.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Gordon Beaton - 28 Jan 2006 15:20 GMT > I'm flexible. All I want to do is avoid javascript including Google > AdSense ads when their AdServer is not available. Pretty well having > an online connection to anything implies Google will be flying. I have local DNS entries (pointing to 127.0.0.1) for many common ad sites so I don't have to see them whether they're reachable or not. Keeps the signal/noise ratio at a reasonable level.
/gordon
 Signature [ do not email me copies of your followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e
Luc The Perverse - 28 Jan 2006 18:27 GMT > On 28 Jan 2006 12:42:23 GMT, "Chris Uppal" > <chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly [quoted text clipped - 29 lines] > > The ads are just little hunks of text, very small a sentence or two. Well if you want to see if google is available then ping them ;)
Reply from 66.102.7.99: bytes=32 time=57ms
 Signature LTP
:) Chris Uppal - 29 Jan 2006 12:01 GMT > If the user is browsing a local copy, but has a 24-7 access, I'd > prefer he saw the ads. That helps pay my bills, but that is not that > important. I don't know how AdSense works, but I see two possibilities.
First, Google might supply a static link of some sort which you embed in your page. So reading the page makes no connection to Google /unless/ the user clicks the link. That would be mildy irritating (simply because they are ads), but is not really so very different from the way that other intended-to-be-local HTML may point to Web-resources. There's nothing (IMO) ethically or technically wrong with that, but it has the severe practical disadvantage that the ads you embed can and will become stale. I would advise against including the ads at all in this case.
Alternatively, viewing the page at all might require data supplied by Google. There is something of a continuum here between simply linking to graphics which isn't included in the downloaded copy, but which must be fetched from Google. That sort of thing makes you look like an idiot (can't be bothered to check and resolve your links). At the other extreme, you might have client-side JavaScript which fetches HTML from Google each time the page is viewed. I'm sorry to be blunt but including the latter in a downloaded copy is /evil/.
Anyway, there is no way of telling whether data is available from Google except by fetching data from Google. (Note that ICMP packets may be subject to different filtering, proxying, etc, from HTTP packets, so "ping"-ing Google is not a reliable indicator).
-- chris
Roedy Green - 29 Jan 2006 13:11 GMT On 29 Jan 2006 12:01:49 GMT, "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly quoted someone who said :
>I don't know how AdSense works, but I see two possibilities AdSense works by you embedding some JavaScript in your html that gets downloaded from Google and executed. It in turn contacts the Google ad server, lets it know which page it is coming from and Google serves up an ad, reasonably relevant to that page based on its last spidering. The downloaded JavaScript looks like this:
/* Google AdSense ad retriever, reformatted as if it were written in Java The orginal is packed with no whitespace. */ (function() { function m(b) { return b!=null?'"'+b+'"':'""' } function C(b) { if ( typeof encodeURIComponent=="function" ) { return encodeURIComponent(b) } else { return escape(b) } } function B(b,a,d) { var f=a.indexOf("?"); var e="http://pagead2.googlesyndication.com/pagead/imp.gif?event="; e+=d; if ( f!=-1 && f+1<a.length ) { e+="&"+a.substring(f+1) } var h='<img height="1" width="1" border="0" src='+m(e)+"/>"; b.write(h) } function c(b,a) { if ( a ) { window.google_ad_url+="&"+b+"="+a } } function g(b,a) { if ( a ) { c(b,C(a)) } } function l(b,a,d) { if ( a && typeof a=="object" ) { a=a[d%a.length] } c("color_"+b,a) } function E(b,a) { var d=b.screen; var f=navigator.javaEnabled(); var e=-a.getTimezoneOffset(); if ( d ) { c("u_h",d.height); c("u_w",d.width); c("u_ah",d.availHeight); c("u_aw",d.availWidth); c("u_cd",d.colorDepth) } c("u_tz",e); c("u_his",history.length); c("u_java",f); if ( navigator.plugins ) { c("u_nplug",navigator.plugins.length) } if ( navigator.mimeTypes ) { c("u_nmime",navigator.mimeTypes.length) } } function y(b) { b=b.toLowerCase(); if ( b.substring(0,3)!="ca-" ) { b="ca-"+b } return b } function H(b,a,d) { d=d.substring(0,1000); d=d.replace(/%\w?$/,""); if ( b.google_ad_output=="js" && (b.google_ad_request_done||b.google_radlink_request_done) ) { a.write('<script language="JavaScript1.1" src='+m(d)+"></"+"script>") } else if ( b.google_ad_output=="html" ) { if ( b.name=="google_ads_frame" ) { B(a,d,"reboundredirect") } else { a.write('<iframe name="google_ads_frame" width=' +m(b.google_ad_width) +"height=" +m(b.google_ad_height)+ "frameborder=" +m(b.google_ad_frameborder) +" src=" +m(d) +'marginwidth="0"' +' marginheight="0"' +' vspace="0"' +' hspace="0"' +' allowtransparency="true"' +' scrolling="no">'); B(a,d,"noiframe"); a.write("</iframe>") } } } function G(b) { var a=null; b.google_ad_frameborder=a; b.google_ad_format=a; b.google_page_url=a; b.google_language=a; b.google_gl=a; b.google_country=a; b.google_region=a; b.google_city=a; b.google_hints=a; b.google_safe=a; b.google_encoding=a; b.google_ad_output=a; b.google_max_num_ads=a; b.google_ad_channel=a; b.google_contents=a; b.google_alternate_ad_url=a; b.google_alternate_color=a; b.google_color_bg=a; b.google_color_text=a; b.google_color_link=a; b.google_color_url=a; b.google_color_border=a; b.google_color_line=a; b.google_adtest=a; b.google_kw_type=a; b.google_kw=a; b.google_num_radlinks=a; b.google_max_radlink_len=a; b.google_rl_filtering=a; b.google_rl_mode=a; b.google_rt=a; b.google_ad_type=a; b.google_image_size=a; b.google_feedback=a; b.google_skip=a; b.google_page_location=a; b.google_referrer_url=a; b.google_ad_region=a; b.google_ad_section=a; b.google_bid=a; b.google_cpa_choice=a } function A() { var b=null; var a=window; var d=document; var f=new Date(); var e=f.getTime(); var h=a.google_ad_format; if ( a.google_cpa_choice ) { a.google_ad_url="http://pagead2.googlesyndication.com/cpa/ads?"; a.google_ad_url+="client="+escape(y(a.google_ad_client)); a.google_ad_region="_google_cpa_region_"; c("cpa_choice",a.google_cpa_choice) } else { a.google_ad_url="http://pagead2.googlesyndication.com/pagead/ads?"; a.google_ad_url+="client="+escape(y(a.google_ad_client)) } var k=a.google_num_slots_by_client; var w=a.google_num_slots_by_channel; var j=a.google_prev_ad_formats_by_region; a.onerror=a.google_org_error_handler; if ( a.google_ad_region==b && a.google_ad_section!=b ) { a.google_ad_region=a.google_ad_section } var i=a.google_ad_region==b?"":a.google_ad_region; var q=false; if ( h ) { q=h.indexOf("_0ads")>0 } if ( q ) { if ( a.google_num_0ad_slots ) { a.google_num_0ad_slots=a.google_num_0ad_slots+1 } else { a.google_num_0ad_slots=1 } if ( a.google_num_0ad_slots>1 ) { return } } else if ( !a.google_cpa_choice ) { if ( a.google_num_ad_slots ) { a.google_num_ad_slots=a.google_num_ad_slots+1 } else { a.google_num_ad_slots=1 } if ( a.google_num_slots_to_rotate ) { j[i]=b; if ( a.google_num_slot_to_show==b ) { a.google_num_slot_to_show=e%a.google_num_slots_to_rotate+1 } if ( a.google_num_slot_to_show!=a.google_num_ad_slots ) { return } } else if ( a.google_num_ad_slots>3 && i=="" ) { return } } c("dt",f.getTime()); c("hl",a.google_language); if ( a.google_country ) { c("gl",a.google_country) } else { c("gl",a.google_gl) } c("gr",a.google_region); g("gcs",a.google_city); g("hints",a.google_hints); c("adsafe",a.google_safe); c("oe",a.google_encoding); c("lmt",a.google_last_modified_time); g("alternate_ad_url",a.google_alternate_ad_url); c("alt_color",a.google_alternate_color); c("skip",a.google_skip); var n=a.google_ad_client; if ( !k[n] ) { k[n]=1; k.length+=1 } else { k[n]+=1 } if ( j[i] ) { g("prev_fmts",j[i].toLowerCase()); if ( k.length>1 ) { c("slot",k[n]) } } if ( h ) { g("format",h.toLowerCase()); if ( j[i] ) { j[i]=j[i]+","+h } else { j[i]=h } } c("num_ads",a.google_max_num_ads); c("output",a.google_ad_output); c("adtest",a.google_adtest); if ( a.google_ad_channel ) { var r=a.google_ad_channel.toLowerCase(); g("channel",r); var s=""; var t=r.split("+"); for ( var o=0; o<t.length; o++ ) { var p=t[o]; if ( !w[p] ) { w[p]=1 } else { s+=p+"+" } } g("pv_ch",s) } g("url",a.google_page_url); l("bg",a.google_color_bg,e); l("text",a.google_color_text,e); l("link",a.google_color_link,e); l("url",a.google_color_url,e); l("border",a.google_color_border,e); l("line",a.google_color_line,e); c("kw_type",a.google_kw_type); g("kw",a.google_kw); g("contents",a.google_contents); c("num_radlinks",a.google_num_radlinks); c("max_radlink_len",a.google_max_radlink_len); c("rl_filtering",a.google_rl_filtering); c("rl_mode",a.google_rl_mode); c("rt",a.google_rt); c("ad_type",a.google_ad_type); c("image_size",a.google_image_size); c("region",a.google_ad_region); c("feedback_link",a.google_feedback); g("ref",a.google_referrer_url); g("loc",a.google_page_location); c("bid",a.google_bid); if ( z(a,d) && d.body ) { var u=d.body.scrollHeight; var v=d.body.clientHeight; if ( v && u ) { g("cc",Math.round(v*100/u)) } } E(a,f); H(a,d,a.google_ad_url); G(a) } function D(b,a,d) { A(); return true } function z(b,a) { return b.top.location==a.location } function x(b,a) { var d=a.documentElement; if ( z(b,a) )return false; if ( b.google_ad_width && b.google_ad_height ) { var f=1; var e=1; if ( b.innerHeight ) { f=b.innerWidth; e=b.innerHeight } else if ( d && d.clientHeight ) { f=d.clientWidth; e=d.clientHeight } else if ( a.body ) { f=a.body.clientWidth; e=a.body.clientHeight } if ( e>2*b.google_ad_height||f>2*b.google_ad_width ) { return false } } return true } function F() { var b=window; var a=document; var d=a.location; var f=a.referrer; var e=null; b.google_org_error_handler=b.onerror; b.onerror=D; if ( b.google_ad_frameborder==e ) { b.google_ad_frameborder=0 } if ( b.google_ad_output==e ) { b.google_ad_output="html" } if ( b.google_ad_format==e && b.google_ad_output=="html" ) { b.google_ad_format=b.google_ad_width+"x"+b.google_ad_height } if ( b.google_page_url==e ) { b.google_page_url=f; if ( !x(b,a) ) { b.google_page_url=d; b.google_last_modified_time=Date.parse(a.lastModified)/1000; b.google_referrer_url=f } } else { b.google_page_location=f; if ( !x(b,a) ) { b.google_page_location=d } } if ( b.google_num_slots_by_channel==e ) { b.google_num_slots_by_channel=new Array() } if ( b.google_num_slots_by_client==e ) { b.google_num_slots_by_client=new Array() } if ( b.google_prev_ad_formats_by_region==e ) { b.google_prev_ad_formats_by_region=new Array() } } F(); A(); } )()
HTML used to invoke this:
<script type="text/javascript"><!-- google_ad_client="pub-3625079171090429"; google_ad_width=180; google_ad_height=150; google_ad_format="180x150_as"; google_ad_type = "text_image"; google_ad_channel=""; google_color_border = "336699"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
There is one more annoying wrinkle in this. Google licensing says you can't change even one comma in the code to invoke the ad. So any solution anyone comes up with has to be sold to Google as the generic solution.
Of course a solution could WRAP Google's code without violating the letter of the agreement. You decide whether to include the ad or not dynamically. I figure if there is some way to get a boolean to say whether ad loading is likely to succeed, you can wrap the Google call to their script in an if.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Luc The Perverse - 29 Jan 2006 18:39 GMT > On 29 Jan 2006 12:01:49 GMT, "Chris Uppal" > <chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly [quoted text clipped - 495 lines] > whether ad loading is likely to succeed, you can wrap the Google call > to their script in an if. What happens when you load a page with the ad but have no internet connection available - if it has no negative consequence, then perhaps you needn't worry about it?
-- LTP
:) Roedy Green - 30 Jan 2006 04:05 GMT On Sun, 29 Jan 2006 11:39:01 -0700, "Luc The Perverse" <sll_noSpamlicious_z_XXX_m@cc.usu.edu> wrote, quoted or indirectly quoted someone who said :
>What happens when you load a page with the ad but have no internet >connection available - if it has no negative consequence, then perhaps you >needn't worry about it? that's the whole point. Your page rendering hangs for a minute or so while the browser waits for the ad to arrive before it will get on with rendering the rest of the page.
It is not like an image where is just leaves a hole. It seems to think whatever that bit of JS will generate is absolutely crucial to rendering the rest of the page.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
steve - 06 Feb 2006 21:35 GMT > On Sun, 29 Jan 2006 11:39:01 -0700, "Luc The Perverse" > <sll_noSpamlicious_z_XXX_m@cc.usu.edu> wrote, quoted or indirectly [quoted text clipped - 11 lines] > whatever that bit of JS will generate is absolutely crucial to > rendering the rest of the page. so why can you not stick it at the bottom of the page?
Roedy Green - 07 Feb 2006 04:04 GMT >so why can you not stick it at the bottom of the page? Because people don't read ads at the bottom of the page.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Gordon Beaton - 07 Feb 2006 07:39 GMT >>so why can you not stick it at the bottom of the page? > > Because people don't read ads at the bottom of the page. Who reads ads on webpages at all?
/gordon
 Signature [ do not email me copies of your followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e
Roedy Green - 07 Feb 2006 12:27 GMT >Who reads ads on webpages at all? I do. The ads it puts on my site are often quite interesting and germane to the micro topic at hand.
I learn things that often spawn new entries.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
David Segall - 07 Feb 2006 13:41 GMT >>so why can you not stick it at the bottom of the page? > >Because people don't read ads at the bottom of the page. It is usually possible to have some content as the last element in an HTML document but display it at the location you want. If putting it last solves the delay problem then the experts at alt.html will solve the display problem even if your current use of divs and/or frames makes it difficult. If, God forbid, you use tables for layout don't confess it at alt.html. :)
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|