I've been struggling with this and can't find a single tutorial on what seems to be a very simple idea.
I've written to the settings in the settings.html file using:
System.Gadget.Settings.writeString("Date1", month + "-" + day + "-" + year);
And that seems to have worked. It displays properly in the settings.
Now, in the main file, gadget.html, I want to pull the data out and display it (not in an input tag). What is the complete code to do this?
Write it to an xml file and use ajax to read it.
Alternatively, write it to a .js file and import it with a <script src=...></script> construct.
Related
I've added a random date param to my CSS and JS files in order to "cache-bust"...
HTML (head)
<!-- STYLE -->
<link href="assets/css/style.css" rel="stylesheet" id="style">
<!-- SCRIPTS -->
<script src="assets/js/scripts.js" id="scripts"></script>
JS (jQuery 3.4.1)
var randomParam = new Date().getTime();
// CSS
var ogCSS = $("head").find("#style").attr("href");
$("head").find("#style").attr("href", ogCSS + "?" + randomParam);
// JS
var ogJS = $("head").find("#scripts").attr("src");
$("head").find("#scripts").attr("src", ogJS + "?" + randomParam);
The CSS file works great. The JS file not so much.
"Network" tab (CSS renamed and called again, JS is not)...
"Sources" tab (JS not called again, has original name)...
I cannot use PHP. I cannot access the server. This is all client-side.
What can I do to make it work? Or is this just how it is?
UPDATE
Forgot to mention that "Elements" in the DevTools show the JS file being renamed properly (see below). It's just not being re-called in "Network" or showing up as being renamed in "Sources". So it's stuck in cache.
I know this question is old, but in case someone comes across it (as I did), the problem is likely here:
ogCSS + "?" + randomParam
That does not create a valid and complete query string. The format of the query string should be:
?<param_name>=<param_value>
but in the code above, we only have ?<param_value>. This means the value will be treated as a name, presumably with a null value, which is generally ignored by most servers I have worked with. To make this correct, you would need to append both a parameter name (often "_" for this use case) and a value, so something like:
ogCSS + "?_=" + randomParam
Hey guys I am trying to learn how to use JSON files. I understand the basics but I am trying to grasp loading them into an HTML file and I am having a couple of difficulties.
The first difficulty I am having is that if I put in the full file extension to load the file I get an error 'expected hexadecimal digit'. I did some research on it and I think it is because in the file extension it is \u so it is expecting a hexadecimal but I am not sure how to work around it.
The second problem I am having is that if I just use the file extension users.json it works in my editor but not in a browser. It is not loading the file at all, the code is fine (I believe). I think it is just not loading the file because of the file extenion.
Suggestions on how to fix my problems? Thanks in advance.
<body>
for output
<div id="forOutput"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var output;
$(document).ready(function(){
alert("JQuery loaded");
});
$.getJSON('C:\Users\Spencer\Desktop\JSJqueryTesting\JSONTesting\users.json', function(data) {
output = data;
for (var i in data.users) {
alert(data.users[i].firstName + " " + data.users[i].lastName+ " " + data.users[i].joined.month);
}
});
$("#forOutput").html("User 1 lastname: " + output.users[1].lastName);
</script>
The file extension is perfect (.json), however, you can't load local files (because of security reasons). If what you are trying to do, were possible, that would mean any website could access all your local files. Now that's really not such a good idea, and therefore (by default) only files that share the same domain(e.g. stackoverflow.com/*) are allowed. This is called Same Origin Policy.
I've done some research on the subject, but can't get a clear answer with how to go about doing this. I have tried the following method:
<script type="text/javascript" src="../binaryajax/binaryajax.js" ></script>
<script type="text/javascript" src="id3.js" ></script>
var file = "mymusicfile.mp3";
// define your own callback function
function mycallback() {
// either call ID3.getAllTags([file]) function to return object holding all the tags
alert(
"All tags in this file: " + ID3.getAllTags(file).toSource()
);
// or call ID3.getTag([file], [tag]) to get a specific tag
alert(
"Title: " + ID3.getTag(file, "title") + " by artist: " + ID3.getTag(file, "artist")
);
}
ID3.loadTags(file, mycallback);
The first method, (getAllTags) doesn't allow my script to run, and the second method returns null for both title and artist on all of my mp3's.
Source of Info: http://blog.nihilogic.dk/2008/08/reading-id3-tags-with-javascript.html
I know these methods are using ID3(v1), so that may be the problem. Either that, or I suppose it's possible by mp3's don't contain ID3 information. But if anyone could provide some insight into how to do this, or how to identify if my mp3's contain ID3 info and whether it's v1 or v2 would be great.
Edit: I should say, I'm accessing the files via Blob URL's because the app that I'm developing let's the user select a directory on their computer and then queries the files for media files. In doing this, you can't access the absolute path of the file, but you still can access the file information and use the file.
For others to use: this worked quite well for me :)
github.com/aadsm/JavaScript-ID3-Reader/tree/master/src use the project repository
I'm using MonkeyTalk IDE Beta2 for testing iPad application. I exported the javascript from the MonkeyTalk IDE and got a new .js file. I am storing the Boolean value of a Verify command in a var and want to see what is its value, and accordingly do custom logic. I tried document.write, console.log and alert used in javascript but got an error that they are not defined. Please help me with this.
Also, is it possible to output the result of a test as XML (as in FoneMonkey) or as an Excel spreadsheet or something like that?
Thank you in advance.
Believe it or not*, but to date there is no way direct way to cause MonkeyTalk to log messages to the console. What you can do, however, is abuse a command like verifyNot which will result in a log message. In a MonkeyTalk .mt this would be done like:
View * VerifyNot Message
I created the following helper script called log.js for this purpose. Timestamps are automatically added by Eclipse, but not elsewhere so I have prepended the time.
load("libs/Executor.js");
function getTimeStamp() {
var now = new Date();
return now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
}
EXECUTOR.defineScript("Log", function(msg) {
this.app.view().verifyNot(getTimeStamp() + ": " + msg);
});
Finally, you don't need the executor boilerplate (only the verifyNot line), but we use that with scripts by Doba in order to be able to organize files in different directories (Doba.js renamed to Executor.js) -- another feature not available out of the box.
* It's almost like GorillaLogic doesn't want you to be able to resolve your own problems. ;)
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.