Jquery excel export is not working in IE9 - javascript

I want to download my HTML table as Excel. For that I used the given code
$('#export').click(function (e) {
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth() + 1;
var year = dt.getFullYear();
var hour = dt.getHours();
var mins = dt.getMinutes();
var postfix = day + "." + month + "." + year + "_" + hour + "." + mins;
var a = document.createElement('a');
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('reportDiv');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
a.download = 'UserMatrix' + postfix + '.xls';
a.click();
e.preventDefault();
});
It's working in Chrome and Firefox but not working in Internet Explorer 9.

You'd need to use an alternate solution for IE9 as it doesn't support the HTML download attribute for the anchor tag.
Here's a popular Javascript option:
https://github.com/dcneiner/Downloadify
It uses Flash, though, which IE 9 would support.

Related

Read a file name by date on javascript

i'm trying to read a file by date with JS
i tried to replace the varable TimeNow without success.
when fo example i make fixed filename it works fine, but replacing the filename with a variable 'TimeNow' it doesnt work.
var prex = document.querySelector('pre');
var DateNow = new Date();
DateNow.setHours(DateNow.getHours()-1);
var TimeNow=DateNow.getFullYear() + "" + (DateNow.getMonth()+1) + "" + DateNow.getDate();
loadCSV("counters_test_directory_${TimeNow}.log");
prex.innerHTML += '\n\n';
prex.innerHTML += TimeNow;
<pre>
</pre>
loadCSV(`counters_test_directory_${TimeNow}.log`);
var prex = document.querySelector('pre');
var DateNow = new Date();
DateNow.setHours(DateNow.getHours()-1);
var TimeNow=DateNow.getFullYear() + "" + (DateNow.getMonth()+1) + "" + DateNow.getDate();
alert(`counters_test_directory_${TimeNow}.log`);
// The source of this function is NOT given.
//loadCSV(`counters_test_directory_${TimeNow}.log`);
prex.innerHTML += '\n\n';
prex.innerHTML += TimeNow;
<pre>
</pre>

issue between browsers with date pad function

I am trying to convert a date to a string and I am finding that my method works in firefox. But the same code comes up with a different and wrong time in both safari and chrome. I've put my code below. Can anyone see what might be wrong.
$(document).ready(function() {
var regLastSynchTime = new Date(item.date);
regLastSynchTimeStr = formattedTradingHourDateAndTime(regLastSynchTime);
});
var formattedTradingHourDateAndTime = function(date){
var d = pad(date.getDate());
var m = pad(date.getMonth() + 1);
var y = date.getFullYear();
var h = pad(date.getHours());
var mi = pad(date.getMinutes());
var ss = pad(date.getSeconds());
return d + '/'+ m + '/'+y + ' ' + h + ':' + mi + ':' + ss;
}
function pad(number) {
return (number < 10 ? '0' : '') + number;
}
Firefox (right)
Safari (Wrong)

How can I get javascript to write dates in my input boxes?

I made this fiddle http://jsfiddle.net/cyrtx7qw/1/ and I cant figure out how to make these two dates write on page load. I need them to check if the boxes are empty and then I want to write the today's date and today-7 respectively.
if ($('#datePickersAppearance').is(':empty')) {
var today = new Date();
var curr_date = today.getDate();
var curr_month = today.getMonth();
curr_month++;
var curr_year = today.getFullYear();
document.getElementById("to").innerHTML = curr_date + "." + curr_month + "." + curr_year;
today.setDate(today.getDate() - 7);
var new_date = today.getDate();
var new_month = today.getMonth();
new_month++;
var new_year = today.getFullYear();
document.getElementById("from").innerHTML = new_date + "." + new_month + "." + new_year;
}
Also, is there a way keep another date after page reload in case I change the default ones? I need the if statement to not trigger then...
filddle
if ($('#datePickersAppearance').is(':empty'))
to
if ($('.datePickersAppearance').val() == '')
document.getElementById("from").innerHTML
should be
document.getElementById("from").value
The biggest problem is that <input> elements do not have a .innerHTML property. It is instead .value.
Your jQuery was traded for JavaScript.
Code was truncated for readability.
Use this instead:
(function loadDates(element){
var from = document.getElementById('from')
var to = document.getElementById('to')
if(!from.value.length && !to.value.length ){
var my_date = new Date()
to.value = my_date.getDate() + "." + my_date.getMonth() + "." + my_date.getFullYear()
// Redefine date object
my_date.setDate(my_date.getDate() - 7)
from.value = my_date.getDate() + "." + my_date.getMonth() + "." + my_date.getFullYear()
}//endif
})();
Updated, you can use sessionStorage to save your dates for page reloads. Also .blur() event handler is used to save data for sessionStorage, so that it's available when the page loads :-) Some other event handlers like .change() could be use as well. Fiddle
var today = new Date();
var curr_date = today.getDate();
var curr_month = today.getMonth();
curr_month++;
var curr_year = today.getFullYear();
var toDate = "";
//check if there's a to Date in sessionStorage
if (sessionStorage.getItem("toDate")) {
toDate = sessionStorage.getItem("toDate");
sessionStorage.setItem("toDate", toDate);
} else {
toDate = curr_date + "." + curr_month + "." + curr_year;
sessionStorage.setItem("toDate", toDate);
}
document.getElementById("to").value = toDate;
today.setDate(today.getDate() - 7);
var new_date = today.getDate();
var new_month = today.getMonth();
new_month++;
var new_year = today.getFullYear();
var fromDate = "";
//check if there's a from Date in sessionStorage
if (sessionStorage.getItem("fromDate")) {
console.log("if");
fromDate = sessionStorage.getItem("fromDate");
sessionStorage.setItem("fromDate", fromDate);
} else {
// actually else part of the code never runs because there's toDate in sessionStorage.
console.log("else");
fromDate = new_date + "." + new_month + "." + new_year;
sessionStorage.setItem("fromDate", fromDate);
}
document.getElementById("from").value = fromDate;
$("#from").blur(function() {
//check that there is data before saving into sessionStorage
if (this.value.length >= 8)
sessionStorage.setItem("fromDate", this.value)
});
$("#to").blur(function() {
//check that there is data before saving into sessionStorage
if (this.value.length >= 8)
sessionStorage.setItem("toDate", this.value)
})

Rename file name with javascript expression

I'm fairly new to javascript and I need to rename or add to an extension of a css and .png file. The script is embedded within an ETL process. I have a variable "prd" that holds the value of the file name that the style.css and picture.png file are derived from and I also need to add a date or time stamp to the end of the extension. Basically I'm wanting to concatenate prd+style_02_06_14.png
Desired results:
Prd = sales_report
File = style.css.
Result = "sales_report_style_02_06_14.png" and "sales_report_style_02_06_14.css"
Here is my code
var sourceCssFile = outputfolder + "style.css";
var destinationCssFile = outputfolder + css_pic;
if(isFolder(destinationCssFile) == false) {
createFolder(destinationCssFile);
var testvar = "inside";
}
destinationCssFile = destinationCssFile + "/style.css";
moveFile(sourceCssFile, destinationCssFile, true);
var sourceImageFile = outputfolder + "picture.png";
var destinationImageFile = outputfolder + css_pic + "/picture.png";
moveFile(sourceImageFile, destinationImageFile, true);
var cont = loadFileContent(output);
var replaceCss = css_pic + "tt+style.css";
var replaceImg = css_pic + "tt + picture.png";
cont = cont.replace("style.css", replaceCss);
cont = cont.replace("picture.png", replaceImg);
var filename = outputfolder + new_str;
Try this:
function formatResult(prd, filename, date, extension) {
return prd + '_' + filename + '_' + formatDate(d) + '.' + extension;
}
function formatDate(d) {
var year = d.getFullYear().toString().substr(2,2);
var month = (d.getMonth()+1) + '';
if (month.length == 1) {
month = "0" + month;
}
var day = d.getDate() + '';
if (day.length == 1) {
day = "0" + day;
}
return month + '_' + day + '_' + year;
}
Demo
http://jsfiddle.net/WHpuU/5/
Nota
alert( 'style.css'.replace(/\.css$/i, '') ); // shows 'style'

Date() function in javascript giving NAN-NAN-NAN in firefox and chrome while working fine with IE

I am calculating on date part through java script , but it is giving NAN-NAN-NAN in Firefox and chrome while working fine in IE . My code is below which is i am using.
var datedisp = $("#txtDateinputBox_startdate").val();
datedisp = datedisp.split("/");
var month = datedisp[0];
var year = datedisp[2];
var dtepart = eval(datedisp[1]);
var moddate = dtepart + SetID - 1;
var finaldate = month + '-' + moddate + '-' + year;
var disp_fdate = new Date(finaldate);
//alert(finaldate);
var disp_date = disp_fdate.getDate();
//var disp_date = disp_fdate.getUTCFullDate();
var disp_month = disp_fdate.getMonth() + 1;
var disp_year = disp_fdate.getYear();
var uidate = eval(disp_month) + '-' +eval( disp_date) + '-' + eval(disp_year);
and then this uidate is using in div creation.
Please Help
Thanks In Advance
This?
var date, i, string;
function date_to_string( date ) {
return ( date.getMonth() + 1 ) + '-' + date.getDate() + '-' + date.getFullYear();
}
date = new Date( '01/27/2012' );
for ( i = 0; i < 14; i += 1 ) {
date.setDate( date.getDate() + 1 );
string = date_to_string( date );
// use string
}
Live demo: http://jsfiddle.net/ekaDg/

Categories