Thursday, November 8, 2018

Load JS File dynamically from JSP file.

function loadJSfile(language) {
var fileref = document.createElement('script')
fileref.setAttribute("type", "text/javascript");
var theURL = window.location.href;
var arr = theURL.split("/");
var result = arr[0] + "//" + arr[2] + "/" + arr[3];
var thePath ="/resources/json_messages/messageJson_"+language+".js";
var theMessageFileURL = result + thePath;
$.ajax({
url : theMessageFileURL,
type : 'HEAD',
async : false,
error : function() {
//language message file not exists
loadJSfile("en");
},
success : function() {
//language message file exists
fileref.setAttribute("src", theMessageFileURL)
if (typeof fileref != "undefined")
document.getElementsByTagName("head")[0]
.appendChild(fileref)
}
});
}

loadJSfile("${pageContext.response.locale}"); //dynamically load and add this .js file

No comments:

Post a Comment

Recent Post

Databricks Delta table merge Example

here's some sample code that demonstrates a merge operation on a Delta table using PySpark:   from pyspark.sql import SparkSession # cre...