Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to find character encoding in any site

    Hi All,
    I need to know, how can we get character encoding in any site through coding.

    Actually i need to add an option in my website, in which i am entering a domain name(url of any website i.e. "http://www.yahoo.com") and through coding i have to find out the character encoding, doctype, frameset.. etc of the entered URL.
    OR
    Are there any such links which can help me out to get these parameters directly by passing the url only.
    Can anyone please help me out to get the parameters of any site.......
    waiting for ur reply`s

    Thanks
    gaurav joshi

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    I Respectfully Disagree

    Create a php page that Finds them out,

    That outputs like so for example
    E.G
    //character encoding||doctype||frameset
    UTF-8||doctype||frameset

    Then AJAX(XMLHttpRequest)http://www.w3schools.com/ajax/
    to get the string from php use some thing likea $_GET['url'] you want to check in your php file,
    Then get your responseText from your AJAX and split('||'); this will then give you an array

    array[0] = Encoding
    array[1] = doctype
    array[2] = frameset

    And do what you will from there -- this is a long way about doing it but it works,
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    I don't see how that is possible without loading the page.

    Using Javascript, this will detect the DOCTYPE:-

    Code:
    <script type = "text/javascript">
    
    function versionInfo()
    {
    this.xhtml="";
    this.version="";
    this.importance="";
    }
    function detectDoctype(){
    var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
    var myversionInfo=new versionInfo();
    //Just check for internet explorer.
    if(typeof document.namespaces != "undefined"){
    if(document.all[0].nodeType==8)
    re.exec(document.all[0].nodeValue);
    else
    return null;
    }else{
    if(document.doctype != null)
    re.exec(document.doctype.publicId);
    else
    return null;
    }
    myversionInfo.xhtml=RegExp.$1;
    myversionInfo.version=RegExp.$2;
    myversionInfo.importance=RegExp.$3;
    return myversionInfo;
    }
    var myversionInfo=detectDoctype();
    if(myversionInfo != null){
    alert(myversionInfo.xhtml);
    alert(myversionInfo.version);
    alert(myversionInfo.importance);
    }
    else{
    alert("There is no DOCTYPE in the code!");
    }
    
    </script>

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by Philip M View Post
    I don't see how that is possible without loading the page.

    Using Javascript, this will detect the DOCTYPE:-

    Code:
    <script type = "text/javascript">
    
    function versionInfo()
    {
    this.xhtml="";
    this.version="";
    this.importance="";
    }
    function detectDoctype(){
    var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
    var myversionInfo=new versionInfo();
    //Just check for internet explorer.
    if(typeof document.namespaces != "undefined"){
    if(document.all[0].nodeType==8)
    re.exec(document.all[0].nodeValue);
    else
    return null;
    }else{
    if(document.doctype != null)
    re.exec(document.doctype.publicId);
    else
    return null;
    }
    myversionInfo.xhtml=RegExp.$1;
    myversionInfo.version=RegExp.$2;
    myversionInfo.importance=RegExp.$3;
    return myversionInfo;
    }
    var myversionInfo=detectDoctype();
    if(myversionInfo != null){
    alert(myversionInfo.xhtml);
    alert(myversionInfo.version);
    alert(myversionInfo.importance);
    }
    else{
    alert("There is no DOCTYPE in the code!");
    }
    
    </script>
    You could try using an Iframe, should be able to get what you need out of that if you can still acceess Iframe sourceCode dont know not used iframes in years
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •