Download ICS String into Mobile with Javascript (Angularjs) - javascript

I'm creating a ics string in my app with this code:
var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me#google.com\nDTSTAMP:" + today
icsMSG = icsMSG + "\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::me#gmail.com\nDTSTART:" + start +"\nDTEND:" + end +"\nSUMMARY:" + $scope.eventContent.text + "\nEND:VEVENT\nEND:VCALENDAR";
This is working fine, since when I want to download on my PC it works fine.
For downloading in PC I'm using
window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));
Apparently this does not work on mobile. On iPhone it does not recognize the file, in Android it downloads the file and you must open it to add to calendar.
I read about webcal:// But it seems to not work sending the string after the webcal://
How can I set the download click in mobile

The spec-compliant newline sequence is \r\n. I doubt that's the problem, but you could try it.
Also, you could try charset=utf-8 (add the dash).
Also note that you have an extra colon character in one of your "mailto" URIs.

Related

Open Explorer window from Website, on mounted drives, including javascript in the link reference to generate the path

In addition to the question here:
Open Explorer window from Website
I'm also having trouble with this, especially because I need to integrate a function into the link that eventually will open in file explore.
Bacially, we have a very simple intranet webpage, to control our cases etc.
Each case has some files in in a folder on the server, but to avoid to many subfolders in one folder, we split them in groubs of 200!
\ip\fileserver\cases\"split-folder"\subfolder
I what to open the folder clicking on the case on our webpage.
The split-folder..is defined in ranges with case-numbers for evey 200 cases (sager in danish)
Like this
\25000-25199\25001
\25200-25399\25399
\25400-25599\25422 or 25555 etc . .
The math to calculate the "split-folder" is simple enough with a script but getting this into a link that will open file explore is not that easy.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction(25555)">Try it</button>
<p id="sagslink"></p>
<script>
function myFunction(sagnr) {
var a = Math.floor(sagnr/200)*200
var b = Math.floor(a+199);
var x = "file://///192.168.15.133/Filserver2016/sager/" + a + '-' + b + "/"+sagnr;
document.getElementById("sagslink").innerHTML = x;
}
</script>
Simple link that Works in IE..but not in firefox og chrome.
sager-full-path
But I can not generate a useful link merging the to!
I have tried evey possible way described here to no awail:
JavaScript function in href vs. onclick
Perhaps I need to revice the function to give the actual link in sted. I also don't what a button but just a generat CASE-Number...that serves as link!
Further more! We mount \\192.168.1.133\Fileserver2016 as Z:
So for our various programs, that use the Z drive path, I would like to open file-explore with the mount path and not the ablosoute path.
We can use IE if nessarry..but I would like i to work on firefox and chrome also
Can this be done!
Ok. So we got it working...sort of ;O)
Our intranet webpage runs in ASP
So the code runs serverside.
Here is the code that works in IE-11.
<%
strSagsNR = rsSag("sagsNR")
Function folderlink(FSagsNR)
a = int(strsagsNR/200)*200
b = int(a+199)
folderlink = "file:///Z:/sager/" & a & "-" & b & "/" & strSagsNR
End Function[enter image description here][1]
%>
To ensure the solution works properly locally and when connected with VPN.
It's necessary to add the server ip to IE-11 Internet security - local Intranet - Webplaces - Advanced
as BOTH FILE AND HTTP! See image.
Security setting in IE
Then you should avoid the remark about this file is dangerous and may harm you computer, and File explore will pop up on the correct path ;O)
I have not found any solution for Chrome or Firefox.

Google chrome replaces C° with C° in javascript file

I tried to run my code in my google chrome browser (version:71.0.3578.98) on a local python https server but when I try to run it the "C°" is "C°". When I lock in the developer tools it is the same but in the code I have on my Desktop it's "C°" and not "C°".
I tried to use diffrent Browsers (FireFox, Opera) but nothing works.
I found out that when I download the chrome plugin (Set Character Encoding) and set the encoding to UTF-8 it works and there stands "C°"
but why is chrome this not doing by default
var temp = 5;
var str = "Now: " + temp + "C°";
console.log(str);
I expected that the chrome browser shows my "Now: 5C°" and not "Now: 5C°".
You could try to use the Hex value to see if it works:
var temp = 5;
var str = "Now: " + temp + "C\xB0";
console.log(str);
If i understood correctly your problem is explain here : http://mc-computing.com/languages/Javascript/Degree_Symbol/Degree_Symbol.html
Please check your character encoding in HTML <head> element.
Add following line in element of your webpage:
<meta charset="utf-8">

LinkedIn Share Url not accepting french contents in IE 11

I am using the below javascript code to open the LinkedIn url with some french content.
var link = 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&summary=' + summary + '&source=testing';
window.open(link, 'share_it', 'width=520,height=570');
But its working fine in chrome with below french contents but not working in IE 11. Its giving the 404 bad request error.
http://www.linkedin.com/shareArticle?mini=true&url=http://testing/&title=PageTitle&summary=énergétique&source=testing
EDIT:
I have tried with encodeURI it opening the window but after logged in the summary is not getting displayed the title only getting displayed. What to do on this one.
Can anyone tell me what i have done wrong.?
I just tried to use it on IE10. The issue is because of the characters in the french language that you must encode. To solve the issue simply use encodeURI() function and you won't get the Bad Request error.
var link = 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&summary=' + summary + '&source=testing';
link = encodeURI(link);
window.open(link, 'share_it', 'width=520,height=570');
I tested it, and it was working fine for me on IE10 as well.

create .ics file on the fly using javascript or jquery?

Can someone tell me if there is any jquery plugin to dynamically create .ics file with values coming from the page div values like there would be
<div class="start-time">9:30am</div>
<div class="end-time">10:30am</div>
<div class="Location">California</div>
or javascript way to dynamically create an .ics file? I basically need to create .ics file and pull these values using javascript or jquery? and link that created ics file to "ADD TO CALENDAR" link so it gets added to outlook?
you will need to make it in ICS format. also you will need to convert the date and time zone; E.G. 20120315T170000Z or yyyymmddThhmmssZ
msgData1 = $('.start-time').text();
msgData2 = $('.end-time').text();
msgData3 = $('.Location').text();
var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me#google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::me#gmail.com\nDTSTART:" + msgData1 +"\nDTEND:" + msgData2 +"\nLOCATION:" + msgData3 + "\nSUMMARY:Our Meeting Office\nEND:VEVENT\nEND:VCALENDAR";
$('.test').click(function(){
window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));
});
the above sample will create a ics file for download. the user will have to open it and outlock, iCal, or google calendar will do the rest.
This is an old question, but I have some ideas that could get you started (or anyone else who needs to do a similar task).
And the JavaScript to create the file content, and open the file:
var filedata = $('.start-time, .end-time, .Location').text();
window.open( "data:text/calendar;charset=utf8," + escape( filedata ) );
Presumably you'd want to add that code to the onclick event of a form button.
I don't have Outlook handy, so I'm not sure if it will automatically recognize the filetype, but it might.
Hope this helps.
From what I have found online and on this site, it is not possible to get this to work in IE as you need to include certain headers to let IE know to download this file.
The window.open method works for Chrome and Firefox but not IE so you may need to restructure your code to use a server-side language to generate and download the ICS file.
More can be found in this question
While this is an older question, I have been looking for a front-end solution as well. I recently stumbled across the
ICS.js library which looks like the answer you're looking for.
This approach worked fine however with IE8 the browser couldn't recognize the file type and refused to open as a calendar item. To get around this i had to create the code on the server side (and exposed via RESTful service) and then set the response headers as follows;
#GET
#Path("generateCalendar/{alias}/{start}/{end}")
#Produces({ "text/v-calendar" })
public Response generateCalendar(
#QueryParam("alias") final String argAlias,
#QueryParam("start") final String argStart,
#QueryParam("end") final String argEnd) {
ResponseBuilder builder = Response.ok();
builder.header("content-disposition", "attachment;filename=calendar.ics");
builder.entity("BEGIN:VCALENDAR\n<........insert meeting details here......>:VCALENDAR");
return builder.build();
}
This can be served up by calling window.location on the service URL and works on Chrome, Firefox and IE8.
Hope this helps.

How do I download JavaScript string as a file

Application requests KML data through AJAX from server. This data is stored in javascript variables, and displayed in Google Earth plugin.
In javascript, how do I provide a link to download the KML data stored in javascript variable (as a string) without requiring a request back to server?
This link:
http://forum.mootools.net/viewtopic.php?id=9728
suggests the use of data URI, but that probably won't work across enough browsers for my needs. Probably simplest just to go back to server to get data again for download, but curious if anyone has pulled this off with javascript.
This will work! It works for me.
enter link description here
`function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// Start file download.
download('hello.txt','This is the content of my file ');
`
Short answer: you can't and still be platform independent. Most browsers just don't allow javascript to manipulate the filesystem.
That said, you might be able to get away with some very platform-specific hacks. For example, IE offers the execCommand function, which you could use to call SaveAs. If you did that within an IFrame that had the data you wanted to save, you might get it working -- but only on IE. Other options (again, I'm going Microsoft specific here) include this Silverlight hack, or ActiveX controls.
I think for full platform compatibility, you're just going to have to suck it up and provide a server-side download option.
[Edit]
Whoops! I didn't do enough due diligence when I went link-hunting. It turns out the Silverlight hack I linked to has a server-side component. Looks like you're pretty SOL.
[Edit2]
I found a nice summary of browser compatibility for execCommand here. Although it lists question marks for the "saveas" command, maybe that might be a good route for you after all. Worth a try, perhaps?
[Edit3]
Well, I decided to do a proof of concept of the approach I suggested, and I got something fairly simple working in IE. Unfortunately, I proved in the process that this approach will not work for Firefox and doesn't appear to work in Chrome/Safari, either. So it's very platform dependent. But it works! Here's a complete working page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Javascript File Saver</title>
<script type="text/javascript">
function PageLoad() {
var fdoc = window.frames["Frame"].document;
fdoc.body.appendChild(fdoc.createTextNode("foo,bar,baz"));
}
function Save() {
var fdoc = window.frames["Frame"].document;
fdoc.execCommand("SaveAs", true);
}
</script>
</head>
<body onload="PageLoad();">
<h2>Javascript File Saver</h2>
<iframe id="Frame" style="width: 400px;">Noframe</iframe><br />
<button onclick="Save();">Save</button>
</body>
</html>
Yeah, I'm afraid you have to pass it back to the server. Make a generic "echo" script that spits out whatever parameters are fed to it.
At least you can force a download with the right MIME type:
"content-disposition","attachment; filename=data.xml"
You might want to check this out: it's called Downloadify. It uses a mix of Javascript and Flash, and can save a string in pretty much any format. Try out the demo and see for yourself!
Check out http://regany.com/blog/2014/05/30/convert-a-string-to-a-download-file-in-javascript/
Enable popups and use the following code:
var str = "the string you wan't to download";
window.open('data:text/plain,' + encodeURIComponent(str));
Probably it would be usefull (JSP variant):
private void printSaveStringButton(String fileName, String content) throws Exception {
//add new invisible container with write / save functions
out.println("<iframe id=\"xmlContentId\" style=\"display:none;\"></iframe>");
//save string in js variable
String jScript = "\n" +
"var SaveHelper = {\n" +
" content : null,\n" +
" saveContent : function(filename, text) {\n" +
" text=(SaveHelper.content!=null)?SaveHelper.content:text;\n" +
" var doc = document.getElementById('xmlContentId').contentWindow.document;\n" +
" doc.write(text);\n" +
" doc.execCommand(\"saveAs\",true,filename);\n" +
" doc.close();\n" +
" }\n" +
"};\n" +
"SaveHelper.content = '" + org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(content) + "';\n";
out.println("<script type=\"text/javascript\">" + jScript + "</script>");
//add button that writes content into iframe container and show save dialog.
out.println("<button type=\"button\" onclick=\"SaveHelper.saveContent('"+fileName+"' )\">Save as...</button>");
}
You could probably use the parseKml function to parse the kml data in the javascript variable rather than trying to store it in a file and modifying it from javascript (which I dont think is possible due to security reasons)
https://developers.google.com/earth/documentation/kml
Frankly, I don't think this is possible. It was never intended that this could be done in javascript.

Categories