...

View Full Version : setting metadata from file



gerble1000
07-13-2012, 11:29 AM
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


var file = "metadata.txt";
document.getelementbyid.metadata.value = file;


i know this code is wrong but is there a way to do this

Philip M
07-13-2012, 12:26 PM
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.

gerble1000
07-13-2012, 12:35 PM
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

Philip M
07-13-2012, 12:37 PM
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. :)

gerble1000
07-13-2012, 12:38 PM
<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

gerble1000
07-13-2012, 12:42 PM
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. :(

Philip M
07-13-2012, 12:42 PM
[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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum