Unfortunately sometime is pretty useful to understand if the JavaScript is executed into Internet Explorer and the version of the browser, you can recover all this information with the usage of regular expressions.
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
var version = new Number(RegExp.$1);
// Do whatever you want with the version information
}
There are several JavaScript libraries that can help you to create an overlay effect, a good one should be
JQuery tools.
A common issue with this library is that the auto load feature allow you to load only once the overlay, second time you try to load it nothing happens and no errors appear.
To solve this issue you can disable the auto load feature in the configuration and manually handle the closure of the overaly binding and unbinding the click event to the document object using jQuery.
var currentOverlay;
function openOverlay(){
var config = {};
config['mask'] = {
// you might also consider a "transparent" color for the mask
color: '#000000',
// load mask a little faster
loadSpeed: 300,
// very transparent
opacity: .6
};
config['closeOnClick'] = false;
config['load'] = false;
config['top'] = '40%';
config['onLoad'] = activateCloseHandler;
config['onClose'] = removeCloseHandler;
$("#theDivYouWantToOpenInOverlay").overlay(config);
currentOverlay = $("#theDivYouWantToOpenInOverlay").data("overlay").load();
}
function activateCloseHandler(event){
$(document).click(function(e) {
e.stopPropagation();
currentOverlay.close();
});
}
function removeCloseHandler(event){
$(document).unbind('click');
}
A common issue in a web application is handling the automatic language detection and the selection of a specific language made by an user.
A possible approach is to keep the language handling client side and handle it through JavaScript. In order to do this you can manipulate the URL and append and recover values using the
jsuri library hosted on google code and encapsulate the language detection in a script included in each page.
The steps the script has to perform are:
- Declare a varbiable to store the current language
- Recover the browser language
- Check if the URL already contains a language query string param
- Change the href value of your page or populate the variable that contains the current language
var currentLanguage;
if (navigator.appName == 'Netscape'){
var language = navigator.language;
}else{
var language = navigator.browserLanguage;
}
if (language.indexOf('en') > -1) currentLanguage = "en";
else if (language.indexOf('it') > -1) currentLanguage = "it";
else currentLanguage = "en";
var uri = new jsUri(location.href);
if(!uri.getQueryParamValue('lang')){
uri.setQuery('?lang=' + currentLanguage);
location.href = uri;
}else{
currentLanguage = getQueryParamValue('lang');
}