I am experimenting with JavaScript again, and wanted to make a clock in an alert box (bookmarklet).
The following code:
javascript:alert(new%20Date().toLocaleString())
will show the time in the format Wednesday, August 08, 2012 12:40:54 AM. However, the time for the clock is not updated because the bookmarklet is just fetching the time. So, are alert boxes able to be updated (like this:)
javascript:alert(setInterval("new%20Date().toLocaleString()",1000))
or is an alert box not able to be updated (it fetches something and then stops executing script)?
EDIT* I have tried the second code line already and know it doesn't work, I only mean for it to be an example of finding a method that allows the time to be updated.
No - alert boxes print a string and their content cannot be changed whilst they are showing.
Use a DHTML dialog simulation instead, such as Facebook's. Since these are just HTML doing the job of native modal functions (e.g. alert()) they are much more flexible.
That's correct. Alert boxes cannot be updated. They also posses another very important feature which is difficult to achieve otherwise in javascript (not that you would want to). They completely suspend execution of any code (because javascript is single threaded) until they are dismissed.
Here is a working example of a javascript clock from github.
He sources the tutorial he used in his Readme.
Related
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 fragment page (jsff) with a numeric keyboard based on buttons surrounded by a client listener which invoke a java script function; every time I click a number it refresh an input text with the value concatenated. I implemented that with JavaScript. Why with JavaScript? Because of the delay using partial triggers showing the value in the input text.
When I test it in the server it works very fine. I click every button and do have a little delay, but It works for the requirements of the develop.
Now, when I insert that fragment inside another jsff which have several components, the result isn't the same. I click every button, and the value is displayed in the input text very fast, but, the button I clicked takes between one and two second to reload for been clicked again. I don't understand what is happening.
Could anyone help me?
Thank you very much.
In Oracle Community I was helped by Florin Marcus:
I quote the answer that works for me:
"Probably you are still propagating the event to the server. You can easily double-check this with a browser plugin like Firefox/Firebug, see if there is any server request being sent.
Normally, you will need to explicitly cancel the event from propagating to the server. For example, if you have a clientListener on a button, you do something like below:
function showPopupFromAction(actionEvent)
{
actionEvent.cancel();
//your logic here
}
"
I have been using the dynArch calendar for some time now. Can't say I've explored all the alternatives but I can recommend this one. Its pretty flexible.
I have run into a problem today that selecting a date was suddenly not updating the text control.
Ultimately, the problem seems to be that when the linked text box is blank, the calendar does not update the linked text box on selecting a date. Further testing reveals that any non-date causes the unwanted behavior.
I have verified that this behavior has been lurking in my production code, so its something I need to address.
I have started walking through the js library to see if i can track it down, but thought I would reach out to the collective as well.
Any help or pointers would be appreciated.
Thanks
In my particular case, the reason I was not seeing the popup was becuase the target text box had an invalid date in it.
I did not research if i could make it pop up a calendar w/ today in it.
I have a jquery/javascript question. For a site I am working on in PHP/JQuery I have the need to create a dialogue box with an ok/cancel button and a message and then submit a form based on if the user says ok or not. I know in javascript I can create a new window that links to a styled page and then I can do a select for if the user hits the ok button and submit the windows parent form using that but the last time I coded something similar to it I felt like it took a lot of lines of code and was wondering if JQuery supported dialogue box creation and if I could do some similar functionality using it (with hopefully less lines of code since everytime I use jquery instead of standard javascript it seems like it really reduces my codebase). If anyone knows of a resource to learn how to do this I would appreciate a link or a second of your time for some pointers.
Thanks!
I think you are looking for something along the lines of the jquery ui dialog.
I am using Selenium to test out a web site. The web site contains a date field, which when clicked, opens a popup from wherein I can choose the date.
My issue is that I wish to select a particular date using the Selenium IDE or Selenese. I have tried various methods, but have not been able to get a correct solution or been able to resolve it, except by manually specifying a date to the field in Selenese script. I am using Java to implement the test case.
An example could be checked by going to any airlines site and clicking on the date field for departure. The popup which comes up, I wish to capture a date on that. This could be a future date or the present date.
You need to implement some code that will navigate calendar to the desired date. Depending on the calendar appearance it may be required to navigate to the next month or year, so you need the code that will determine what needs to be done and then emulate required events for Selenium.
We had the same task in our tests and we end up with either selecting today's date or by entering the date into the field directly. We also made a code that will allow to select any date on the calendar by we did this only because we needed to test the calendar widget and we were the authors of the widget so we knew how it was made. However it resulted in writing a lot of code
Selenium IDE is limited in its ability to handle javascript. I've worked around it at times
by putting custom links in that do customized GETs, but it's a hack.
You could look at Sahi, which can do it. I haven't tried it though.
http://sahi.co.in/w/