Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Fetching the document mode of IE in java

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Fetching the document mode of IE in java

    HI all ,
    I am trying to fetch the browser version as well as document mode of the browser i.e IE from the given function.I knew that in javascript we can use document.documentMode to fetch the doucment mode of IE.but is there any way to do it in java ? I have the userAgent string fro the HttpServletRequest ,but i cannot use it to fetch the document mode.I have used ScriptEngine to execute the javascript inside the java code ,but It is giving exception that the document element is not defined.Kindly help please






    private float getIEVersion(String useragent) 
    	{
    	  ScriptEngine engine = 
                    new ScriptEngineManager().getEngineByName("javascript");
    		String docversio = null;
    		String script = "function documentversion() { return document.documentMode }";
    		try {
    		     engine.eval(script);
     
    		     Invocable inv = (Invocable)engine;
     
    			try {
    				docversio = (String) inv.invokeFunction("documentversion");
    			} catch (NoSuchMethodException e) {
    				System.out.println("No such method");
    				e.printStackTrace();
    			} 
     
    			if(null != docversio)
    			System.out.println("the document version is "+docversio);
    		} catch (ScriptException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} 
     
    		float ieVersion = -1;
    		if (useragent != null && useragent.length() > 0) 
    		{
    			useragent = useragent.toLowerCase();
    			if (useragent.contains("msie")) 
    			{
    				Pattern iePattern = Pattern.compile("msie ([0-9]{1,}[\\.0-9]{0,})");
    				Matcher m = iePattern.matcher(useragent);
    				if (m.find()) 
    					ieVersion = Float.parseFloat(m.group(1));
    			}
    		}
    		//System.out.println("The ie version is "+ ieVersion);
    		return ieVersion;
    	}


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Fetching the document mode of IE in java

    'document' is undefined because this is executing on the server side. To get the clients browser you will need to pass document.documentMode to the servlet as a parameter. You can scrap the ScriptEngineManager.

Similar Threads

  1. Set Footer and Header in Document using Java
    By raghu3.ankam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 24th, 2014, 07:01 AM
  2. Code for fetching harddisk id in all Operating System
    By Indrajeet in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 20th, 2013, 11:21 PM
  3. Making the pieces fit together in Java (Document vs File)
    By TenLeftFingers in forum Object Oriented Programming
    Replies: 6
    Last Post: November 19th, 2012, 12:06 PM
  4. Replies: 0
    Last Post: September 15th, 2011, 06:44 AM
  5. Works on debug mode but not on run mode
    By alfonsoraul in forum Member Introductions
    Replies: 0
    Last Post: April 14th, 2010, 02:58 PM

Tags for this Thread