Script For Detecting Availability of XMLHttp in Internet Explorer

Having the XMLHttpRequest API available is key to any ADF Faces Rich Client application. Unfortunately, it is possible for users to switch off this option in Internet Explorer as a Security setting. Without XMLHttpRequest available, your ADF Faces application will simply not work correctly, but rather than giving the user a bad user experience wouldn't it be nicer to tell them that they need to make some changes in order to use the application? 
Thanks to Blake Sullivan in the ADF Faces team we now have a little script that can do just this.
The script is available from the sample code page here, just look for the browserCheck.js sample - This is what you'll need to add to your project.
The best way to use this script is to make changes to whatever template you are using for the entry points to your application. If you're not currently using template then you'll have to make the same change in each of your JSPX pages.
  1. Save the browserCheck.js file into a /js/ directory under your HTML root within your UI project (e.g. ViewController)
  2. In the template or page, select the <af:document> object in the Structure window.
  3. From the right mouse (context) menu choose Facet and select the metaContainer facet.
  4. Switch to the source code view and locate the metaContainer facet. Then insert the following lines (I've included the facet tag for clarity but you'll already have that):
      <f:facet name="metaContainer">
        <af:resource type="javascript"
                     source="/js/browserCheck.js"/>
        <af:resource type="javascript">
           xmlhttpNativeCheck(
                     "help/howToConfigureYourBrowser.html");
        </af:resource>
      </f:facet>

Note that the argument to the xmlhttpNativeCheck function is a page that you want to show to the user if they need to change their browser configuration. So build this page in the appropriate place as well. You can also just call the function without any arguments e.g. xmlhttpNativeCheck(); in which case it will pop up default instructions for the user to follow, but not redirect to any other page.
Comments:

Any chance you could post the javascript file? Oracle sample code doesn't seem to be working.

Posted by BW Bray on September 12, 2011 at 05:27 PM BST #

Here's the script:
/**
* JavaScript function to check to see if the native XMLHttpRequest function is enabled in IE
*/

function xmlhttpNativeCheck(redirectToPage) {
if (!window.XMLHttpRequest) {
// Check if this is internet explorer
if (navigator.userAgent.toLowerCase().indexOf("msie") != - 1) {
// If a help page has been specified go there
if (redirectToPage != undefined) {
window.location = redirectToPage;
}
else {
// tell user to fix his page. This would be translated and might need different instructions per IE version
// All in all it's better to use the redirectToPage option to send the user to a more comprehensive help page
alert("This page requires that Internet Explorer native XMLHTTP be enabled." + " Open 'Tools' > 'Internet Options'. Select the 'Advanced' tab and ensure that the" + " 'Enable native XMLHTTP support' box is checked under the 'Security'" + " subsection.");
}
}
}
}

Posted by Duncan on September 19, 2011 at 04:04 AM BST #

in the second step:
2- In the template or page, select the <af:document> object in the Structure window.

I am using a template but there is no <af:document> tag? How can we add it javascript in the template

Posted by guest on January 08, 2012 at 04:10 AM GMT #

I'm not sure you need this in the template - after all it's a check that you only need to make once and at the entry point of the app so you can add it to the document tag of specifically that page.
You can of course use an af:resource tag to add it in the template as well if you really want to.

Posted by Duncan Mills on January 09, 2012 at 02:36 AM GMT #

Thank you,
it is clear now, I will add it in my entry page.

Posted by guest on January 09, 2012 at 02:47 AM GMT #

Post a Comment:
Comments are closed for this entry.
About

Hawaii, Yes! Duncan has been around Oracle technology way too long but occasionally has interesting things to say. He works in the Development Tools Division at Oracle, but you guessed that right? In his spare time he contributes to the Hudson CI Server Project at Eclipse
Follow DuncanMills on Twitter

Note that comments on this blog are moderated so (1) There may be a delay before it gets published (2) I reserve the right to ignore silly questions and comment spam is not tolerated - it gets deleted so don't even bother, we all have better things to do with our lives.
However, don't be put off, I want to hear what you have to say!

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today