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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    131
    Thanks
    11
    Thanked 0 Times in 0 Posts

    setting metadata from file

    is there a way to set the index.html metadata from a txt file in the same folder.
    im thinking maybe with jquery or something.
    the reason is i would like to limit the editing on the index.html and let the admin take care of this.


    something like this
    Code:
    var file = "metadata.txt";
    document.getelementbyid.metadata.value = file;
    i know this code is wrong but is there a way to do this

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Quote Originally Posted by gerble1000 View Post
    i know this code is wrong but is there a way to do this
    No. JavaScript running in a browser is a client-side language. JavaScript does not have any commands for reading or writing files. Modern browsers can read files on the server using an Ajax call, but otherwise JavaScript has no capability to read from, write to, modify or delete a file (except a cookie), communicate with the server, access a database, the client's operating system or the Windows registry, or alter the default behaviour of the browser.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder
    Join Date
    Nov 2011
    Posts
    131
    Thanks
    11
    Thanked 0 Times in 0 Posts
    could i get it to just read the file and set the metadata as i could write a perl script for the rest.
    how would this ajax call go

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Quote Originally Posted by gerble1000 View Post
    could i get it to just read the file and set the metadata as i could write a perl script for the rest.
    how would this ajax call go
    The answer is still no.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Regular Coder
    Join Date
    Nov 2011
    Posts
    131
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Code:
    <script language="Javascript" type="text/javascript">
    <!--
    
    function createRequestObject() {
        var tmpXmlHttpObject;
        
        //depending on what the browser supports, use the right way to create the XMLHttpRequest object
        if (window.XMLHttpRequest) { 
            // Mozilla, Safari would use this method ...
            tmpXmlHttpObject = new XMLHttpRequest();
    	
        } else if (window.ActiveXObject) { 
            // IE would use this method ...
            tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
        return tmpXmlHttpObject;
    }
    
    //call the above function to create the XMLHttpRequest object
    var http = createRequestObject();
    
    function makeGetRequest(wordId) {
        //make a connection to the server ... specifying that you intend to make a GET request 
        //to the server. Specifiy the page name and the URL parameters to send
        http.open('get', 'definition.jsp?id=' + wordId);
    	
        //assign a handler for the response
        http.onreadystatechange = processResponse;
    	
        //actually send the request to the server
        http.send(null);
    }
    
    function processResponse() {
        //check if the response has been received from the server
        if(http.readyState == 4){
    	
            //read and assign the response from the server
            var response = http.responseText;
    		
            //do additional parsing of the response, if needed
    		
            //in this case simply assign the response to the contents of the <div> on the page. 
            document.getElementById('description').innerHTML = response;
    		
            //If the server returned an error message like a 404 error, that message would be shown within the div tag!!. 
            //So it may be worth doing some basic error before setting the contents of the <div>
        }
    }
    
    -->
    </script>
    this is the code i think i need to modify.
    how would you set the metadata once i have the file into variable

  • #6
    Regular Coder
    Join Date
    Nov 2011
    Posts
    131
    Thanks
    11
    Thanked 0 Times in 0 Posts
    i am now quoting somes post on another forum i just found
    "This would be pointless because 90% of the time, meta tags are used for search engines. Search engines crawlers don't run JavaScript."

    if this is the case then it would be pointless.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,253
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Quote Originally Posted by gerble1000 View Post
    [CODEthis is the code i think i need to modify.
    how would you set the metadata once i have the file into variable
    You don't. Not possible. Javascript cannot access or change the metadata. And as you say, pointless. OK?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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