Archive for the ‘programming’ Category
JavaScript, JQuery and Leading Browsers– behavioural differences
It’s the second decade of the 21st century and the browser manufacturers STILL can’t agree on standards.
Here’s a simple piece of coding – almost too simple – it uses the JQUERY library (not shown) to simplify cross-browser coding.
<script language=”javascript”>
function alertMsg()
{
var gm=”/admin/ajax_keepalive.asp”;
$.get( gm, function(data) { $(“#myTimer”).html(data); } );
var t=setTimeout(alertMsg,10000);
}
alertMsg();
</script>
This simple piece of code works as follows…
The purpose of the code is to put an incrementing number into my web page… that’s all – but the number is coming from another page.. and the purpose of this is to stop session timeouts by making sure that even when the user is idle – something is happening.
The function alertMsg() sets up the address of a web page which returns nothing more than an incrementing number. Every time you call the page, it returns an incremented number – and the jQuery then forces that number into a SPAN on my web page. You’ll note that the following line sets a 10 second timeout to call the same routine, over and over.
Finally the routine is called – which puts up the display and sets the timer to call the routine in 10 seconds – ad-infinitum.
Except that it works a treat in Firefox – and doesn’t work at ALL in Internet Explorer.
There are TWO unrelated issues here – showing the differences between the browsers.
Firstly in Internet Explorer, the routine is never called (alertMsg()) in the first place – because the DOM is not ready when the routine runs – so the timer never gets set. It would not matter anyway because Internet Explorer CACHES the call to ajax_keepalive() – and so it would return the same value instead of an incrementing value – EVEN THOUGH calling this page directly in either browser WORKS a TREAT.
Here’s a version that works for both (differences show in orange)…
<script language=”javascript”>
function alertMsg()
{
var gm=”/admin/ajax_keepalive.asp?r=” + Math.random();
$.get( gm, function(data) { $(“#myTimer”).html(data); } );
var t=setTimeout(alertMsg,10000);
}
$(document).ready(function()
{
alertMsg();
});
</script>
Note that I’ve added a random number onto the end of the page call – as a parameter which never gets used – but it prevents cacheing… also I’ve wrapped the function call in a jQuery document ready function that makes sure this code (AlertMsg()) does not run until the DOM is ready.
Firefox does not need any of this stuff – Internet Explorer does – and we’re not talking old rubbish here – we’re looking at Firefox 7.01 and IE 9 !!!
The Digital Economy Bill
The bill is an attempt by the government to crack down on internet copyright infringement, not a bad idea in itself, but as usual with this government, it is the implementation that’s totally messed up. By attempting to place the burden on the provider, the bill, which went through the house of Lords this week and looks set to fly unless someone DOES something, is likely to affect, Internet Cafe, Hotels, service providers, trains and the PUBLIC.
Anyone offering WIFI access – how about the COUNTLESS FON USERS !!???!!
The bill could also affect any small business that allows for home working… the list goes on and on and on… apart from anything else, why on EARTH should any hotel, faced with the possibility of having to police the use of their WIFI – which is WAY beyond the technical or managerial skills of your average hotel, why should they BOTHER to continue to offer free WIFI.
We’re still living in the DARK ages in the UK and this bill is about to make it a LOT WORSE. What about the free WIFI on TRAINS??!!??
If ever there was an example of the government trying to turn us all into willing participants in a POLICE STATE you are now looking at it!!!
You may find these links useful…
http://www.guardian.co.uk/uk/2010/apr/08/internet-piracy-bill
http://www.fsb.org.uk/policy/assets/0310%20digital%20economy%20bill%20briefing.pdf
http://www.openrightsgroup.org/
http://computingblogs.typepad.com/peter_scargill/
and to gripe to your MP
Digital What?
According to the “Digital Britain” report, around 11% of homes cannot currently achieve speeds of 2Mpbs – and so the proposal is to fix faulty wiring and use satellite to fill in.
Well, the faulty wiring bit I can go along with – but satellite – I’ve had various forms of satellite and no amount of technical progress is going to fix the fact that the satellites are thousands of miles up in the sky and the latency makes for example Skype conversations virtually useless. Also one of the original satellite companies recently contacted me and I checked on their pricing – they are STILL taking us to the cleaners – so all that will happen now is that tax-payers will give them their money as against the privileged few who can afford them – this is NOT the solution – there are a boatload of alternatives – WIMAX where a large aerial, say at the top of a hill supplies a wide area…. is one solution, high altitude balloon is another (same idea as satellite without the thousands of miles) – but the real solution is to force BT to do their job properly!
Ofcom will now be able to force service providers to notify households who are downloading and sharing content illegally – HURRAY they’ve finally done what they’ve been wanting to do for years – control the INTERNET – this is big-brother CHINA-STYLE!! What next, selective control of material to make sure our nation sensibilities are not offended? Social workers calling at your door because you’ve been reading too much right-wing material?
As for 3G networks – which really are pathetic in the UK, the proposition will “provide certainty for investment and an incentive towards greater roll-out” – what? sorry? Last time I contacted Orange to see why we didn’t have coverage in our village they insisted they would LOVE to provide coverage but every time they’d tried to find somewhere to site a masts the “mothers against masts” brigade had stopped them. Until we breed ignorance out of people we’re never going to roll out proper 3G or proper solar and wind power systems for that matter in the UK, instead we’ll just continue to piddle about. We need a government that is brave enough to take a lead on this an ensure we have universal 3G coverage and policies which ensure the prices are practical – only THEN will we have a truly “digital Britain”.