I've created a loop in JS and have a condition that say if(minute === 15), once the clock hits 15mins past (whatever) the condition is met.
I want to make that "15" a variable that can be changed from another webpage.
website.com/alarm
Contains the loop
website.com/alarmConfig
Contains a text field used to set the minute.
I originally was going to make that script read a notepad that has the value in it, but because the page will be running on a range of devices I need those browsers to be able to do that.
What would be the simpliest way of doing this? Doesn't need to be in real-time
You can't do it. But you can use cookies or localStorage to share these variables.
For simple synchronous storage access HTML 5 introduces the localStorage attribute on the Window object:
localStorage["status"] = "Idling.";
You can make an Ajax call to "website.com/alarmConfig" webpage and then retrieve the value of the text field used to set the minute and then update the loop in "website.com/alarm".
Also, you will make the call after the said duration is over and once you retrieve the updated value, you can run the loop again.
Related
Pretty sure I have to use javascript for this, but double checking anyways.
Wondering if anyone has figured out a no script way to use CSS counters as the id property value for elements without using javascript? Or if javascript is necessary is it possible to grab the counter value without recreating the counter?
For example I've created this component test page. You'll notice that each When / Then test has a css counter generated number. I want to use that counter value as the id attribute value of the corresponding element. That way links to tests can be sent like this:
https://superflycss.github.io/component-test/target/test/html/#2
That would scroll to the second test when entered in the browser.
I add some compile time scripting to superflycss/cli to enable this, but wanted to make sure there's no dead simple option first.
So I have a function and I want this function to run after(like 10 min) user selects it. While timer(10 min) is counting down to run this function, I want timer to be shown to user in a spesific view. I have all functions and views set up for this aim just I dont know how to put timer and show it to user.
https://www.w3schools.com/howto/howto_js_countdown.asp
I checked this but I cant properly put PHP values into Javascript so I cant make it. I also thought about cron jobs but I am not sure how I can do it there.
1) I want a function to run after a spesific time.
2) Additionally I would really like to show this time as a countdown to user.
If you want function that will run after certain time at serverside - check laravel.com/docs/5.5/scheduling. It's really easy to setup.
You can create Laravel's with your function that will repeat every ten minutes or whatever you want. That job would get date from database and check if function should be executed - if so, mark database record with date as executed and call your function.
For timer, in my opinion best approach is to make AJAX call to some API which would return your date for timer, then all need to be done is assign it to a javascript's variable.
Another way is to render view template also with date, make it invisible with CSS display: none and then retrieve it from DOM for your JS timer.
You would need make some changes to timer at w3schools. Add some conditionals to check how much time left, and if it's =< 10 minutes, append timer to the DOM.
So Lets say I have a site like this one http://www.worldtimeserver.com/
and I want somehow to get the value of the time every second and write that value in a .txt file. I was going to use a OCR(optical character recognition) software for this job but ..... in the end this option wasn a good choice because I could not rely on exact position of the clock.
Then I started to think "is there a way to inject/put some code in the browser that would do this?". When I inspect the web-page (in Chrome) I saw that the Div containing the time has an id="theTime". So is there a way to do this? I have some basic experience in JS & DOM ... but this I have no idea how to do or from where to start. Also i would like to point out that I need to rely that the script will do this job for hours and hours and that the value of the clock is set by outside (a server).
If the value does not require the browser to refresh to change the value.. you can save it using localstorage and later copy paste it in a txt file
this is a possible duplicate.
Get value of input field inside an iframe
use an iframe (you can hide it if you don't want users to see it).
I have a requirement where clicking on an icon should open a new window where the user will be able to view and edit certain fields. After the user closes this window and comes back to parent window, the icon color and text should be changed( for eg:- if the user has removed certain data, the icon will change to red color and text is set to null. If the user presses cancel button, nothing changes)
I am planning to implement this using a body onload function which essentially checks with the database using AJAX requests to see if the user has changed the data, then accordingly change the icon and text.
But, I see 2 problems in this approach
1. There will be a AJAX call even if the user has not changed anything.(ie. pressed Cancel button)
2. AJAX is called every time the body is on focus. Eg:- He may be working on some other page (or a different browser altogether) and comes back to this, resulting in an AJAX call.
Can anybody suggest a better approach.
I am using Javacript, JSP, Java
Two ways to implement this
Method 1
You know the methods which changes the database in the opened form. Suppose you have a delete method, write an additional window.opener.location.reload() after the method. The downside is that opener(parent window) gets reloaded every time you change something in the child window. Which is unnecessary.
Method 2 - Using cookies
I am using MDN's A little framework: a complete cookies reader/writer with full unicode support for creating cookies. The plan of action will be this. Create a cookie and set a value for it like this after you change anything in the child window and update it in the database like this docCookies.setItem("isChildFormUpdated", "yes");. You can use the same cookie for every action you do. Now when you navigate back to the parent form, do this.
$(document).ready() {
$(window).focus(function () {
var formCookie = docCookies.getItem("isChildFormUpdated");
if (formCookie !== null && formCookie == "yes") {
//resetting the cookie. you can also remove the cookie
docCookies.setItem("isChildFormUpdated", "no");
//docCookies.removeItem("isChildFormUpdated");
// your ajax call comes here
//or you could simply reload the form so that we get fresh data
//window.location.reload(); // it will be heavier
}
});
});
I hope you get the basic idea.
I think the easiest way to do this would be to set a cookie (learn how here). You can then have the two windows communicate between each other. This wouldn't be AJAX, but it will most likely work.
Another nice way to create a popup-like box is by using a modal box. These can be complicated but they look very nice. You have to make a jQuery plugin in, but you can take the one here and learn how it works. Good luck with your requirement.
I am trying to create multiple counters but not get done...
I have 4 states for every user in my page and I want to count time invested by the user in a single state..All the states are changed by user ..when users change their state the counter(up)
...start and reset again and count up to the next status change....
kindly help me as soon as imposable...
I had try many code but nor get done because the user are many and the counter code is one and the variable is one for each counter....the no of user are ..dynamic...
Yes, if your trying the same in web application where multiple users are logging then surely it will get wanish .. for that you need to maintain the session for each counter (if possible).
or one suggestion will be at a time of click call callback(jquery/ ajax) which will start the counter and automatically it will get reset . but yes you need to maintain that as per session wise.
then there will be a one way to maintain that counter value in session for that user and on page load you can again start with the same count.
Here i would suggest you to do that using Cookies by maintaining the counter value at client side.
You can use $.cookie("key", value) to set the value, and $.cookie("key") to get the saved value.
Also refer the article on jquery cookies. http://www.electrictoolbox.com/jquery-cookies/