Is there a way to trigger an event when file is created in some directory? Similar to jquery click function, I want to have something like:
$(document).ready(function () {
$(this).fileCreated(function() {....}
});
I'll need to react to RF card reader, which will store data to file, and this solution (if it is possible ofc) would probably be the easiest to implement.
I'll need this for a web service whivh will only run locally with no access to source code or anything. Security shouldnt be a problem.
#t.niese Pointed out my bad solution.
After reconsidering the issue I would likely have an on click listener in which the callback checked to see if the file path for the new file was to the directory of concern before doing anything else. That way you could also make functions for future paths using the same listener and callback function if you wanted.
Recognizing you want the listener to focus on actual file creation I double checked on JS events and found onsubmit as the closest to what you're looking for, but it appears to simply work similarly to on click anyway.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onsubmit
If a request is being made by your application after reading an RF card I don't see why you couldn't use .ready if you incorporate it into some html response.
The only other possibility I can see would be to find some framework that expands on available events. I know Backbone.js does some extra stuff with events.
Related
I am creating an extension to track changes that have been made to any JS or CSS file of a page via DevTools. At will, I want to then push those changes - as a whole file if necessary, but changed-elements only would be nice - for the purpose of sending directly to my server to be handled.
My question pertains specifically to this:
Image of DevTools Changed Tab
Can I, via an extension, hook into the Changes tab in order to take those changes and process them? (Or is there a similar process that can handle this manually?)
This ideal output I'm hoping to find or be able to get to would be something like this:
{
fileName: nameofeditedfile.css,
change: [SomeComplexObjectWithTheSpecificChanges]
}
I'm aware that I can save these files locally and then do as I please with them, but for multiple reasons that's definitely NOT the route I want to go.
Let me know if I need to include a more specific example or other details!
I have a website structure
/
/users
/users/wishes
I am using ExpressJS, Jade, and vanilla JS for front-end with 2 separate js files using window.onload function to set up my onclicks. I am expecting that my clients first open / and after this they proceed to the other pages. I have 3 views for each of the pages. Since the website is pretty small I decided not to do overkill by using a JS Framework.
Now I want to minimize my JS files inside a single one, as usual, and load everything in the root. However, it does not seem to work. How should I approach this problem?
You can listen for event instead of replacing window.onload function.
window.addEventListener('load', function() {
console.log('here you go !');
})
But take note, that if listener will be added after event fires, it wont execute.
I'm currently working on a PHP 5.3 based CMS. A lot of actions are called using GET Parameters.
Example:
index.php?action=create_module
adds a certain module to the database and displays the module structure again. There are also functions (triggered by simple links, no POST request) for removing and ordering modules, working the same way with GET parameters.
Problem with this: If the users clicks on History Back after two actions on that page, the whole action is triggered again, which I would like to avoid.
How can I solve this issue? Searched the internet already, but with no satisfying results.
Is there a jQuery function which can remove this ?action parameter when using the browser Back button?
If not, can I prevent the browser from going back?
Is there a way to trigger this "Page has expired" notice?
Different approach on the PHP side?
Note: Header("Location:..") is no option, and I would like to avoid AJAX here.
Thank you for your help!
You could add an event listener on 'onpopstate' to clean window.location.search which holds the parameters, see http://html5doctor.com/history-api/ to get more info about HistoryAPI.
I know this question might trigger some reactions of the type "View-model separation is good". So please be aware that I am aware of that :).
So, when activating a route, Durandal obtains a view by doing a very simple get request, just using something like "view.html" in the get url.
Question: is it supported to add a parameter to the url? So as to have: "view.html?id=4".
I know it's not the point but I want to do it anyway. Why? Because currently, an important part of the js code happens in the viewAttached method. I am using a js library for adding stuff to the page, that needs access to the dom. So when reaching the page, one can see modifications taking place, and it's not nice to see the page changing like that. So I'd prefer that stuff to happen on the server, using a .Net control.
Thanks,
Nicolas
I think that you can find all the information that you need in this other question: Pass data in DurandalJS to other view
I have a relatively large (in terms of memory use and code size) JS function (running in IE/FF) that I use only occassionally (like, a couple of times per day). I think I can get rid of it when I'm done with it by nulling out its function (using the variable name of the 'function object', as it were).
I am fuzzy though on how I would get it back, supposing maybe some time later I wanted to do it again. How would I load JS on the fly from a URL like the 'script' tag does?
Does this whole line of reasoning make sense?
It's a tad hacky, but there are two ways:
Use DOM methods to insert a script tag into the page to a file that has that function in it. You might need to add a query string so that it thinks it's a new javascript file (like function.js?(random number))
Use AJAX to download the file with the function and eval(); it
The only real way to do this is to insert a script element into the document dynamically using JavaScript with a link to a script file containing your function, causing the script to be loaded. One caveat: you must make sure that the filename has the time appended as a query string, otherwise cache unfriendly browsers like Internet Explorer will not reload the script again.
Like others have said, the best bet is to go ahead and insert a new script tag into the page with some kind of query parameter to avoid caching issues. If you're using a JS Library, this technique is actually called "JSONP"; jQuery in particular has a nice method for doing this that gives you an easy way to attach a callback function and such. If you write your own native version, you'll need to watch the readystate of the new script node to know when it's actually loaded.
That said, one thing I'm curious about - and anyone else, please correct me if I'm wrong - why not use the "delete" keyword to kill your function, instead of nulling it out? Something like...
function myFunction() { return; }
Then...
delete myFunction;
Seems to be a more efficient way of cleaning things up, at least from my perspective.