How to read a properties file in javascript from project directory?

前端 未结 5 1424
你的背包
你的背包 2020-12-05 15:23

I\'m building a Chrome Packaged App. I want to put the script configuration if a config file in a resource directory and on startup want to read that by Javascript.

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 15:51

    You can use messageResource.js, a simple javascript library created by me for loading properties file.

    1) Include messageResource.js in your index.html.

        
    

    2) You can get key-value pairs of config.properties from main.js using the following code.

    // initialize messageResource.js  
    messageResource.init({
      // path to directory containing config.properties
      filePath : 'resource'
    });
    
    // load config.properties file
    messageResource.load('config', function(){ 
      // load file callback 
    
      // get value corresponding  to a key from config.properties  
      var value = messageResource.get('key', 'config');
    }); 
    

提交回复
热议问题