Fix JavaScript code to cope with URL parameters