I am wondering how to make a JavaScript popup message (display for 5 seconds) when a database input for specific users have changed? Kind of like the Xbox live achievement message that comes up each time you do a specific task, but i want mine to check if the level for a specific user changes and then have a popup message saying "Congratulations on reaching level x". I'm going to have a popup message for other things than just level as well so it would need to be easy to design.
I couldn't find anything online so if any of you have any suggestions, please leave me some links.
either use a timer and ask via ajax in an interval for new popups
or use websockets/websocketserver to push that info to the client
Related
I looked on SO, here, a few other places & ... cluelessness set's in.
What is the structure of the Facebook " Like " Button found all over websites ?
Is it a Social Bookmarking, Browser Button kind ?
Is there a step by step process (without using FB Api) to make my own kind of button.
How to design & implement a Like Button ?
I want my own button with similar functionality as FB but NOT related or developed on their platform! I am trying to input this in iWeb'09 as a html widget.
I've done this successfully. Here's how i did it:
You have a table in a database called "likes" with fields username,postid (and date, id if you want too)
Each post/blog/article should have its own id.
When someone likes a post/blog/article, you take the id of the post/blog/article and the username who liked it and check the likes database to see if it already exists. If it already exists, you remove the like. If it does not exist you add a like.
For example with AJAX, this is how i did it specifically:
I have a blog post with id 6.
Jonathan likes this post.
These 2 variables are sent via a post form and wait for a response, likes logic checks database to see if this record already exists in likes table (username,postid) values ('Jonathan', 6) if the response is 1 (or true), then i update the div number for the likes button from whatever value was there originally and add 1. If the response is 0 (or false) then i take the original value in the likes counter and remove 1.
To answer your question consider what happens with buttons and then go into like buttons.
Pressing a button triggers an event on client which may or may not update a server somewhere to notify that a button has been pressed for such and such intention. You can send a lot of extra info with this event like when and where who and why etc
Like buttons usually have extra info on who liked it and what they like. In order to get that you might ask people to sign in or provide some kind of input to identify them.
Take a real world example of a like button you can implement in say javascript using any server side technology
Whoever install your script will be able to see the button. You may form it with any css or your javascript can simply load an iFrame from your server or append elements to DOM to show this button
When clicked it calls your server with person's info or at least the page url where it was called. For example google analytics uses a unique ID associated with domain url to track visitors.
when you recieve this call you can update your database/storage or anything with the tick mark that button on abc site has been pressed so lets update their likes or dislikes.
If you want your javascript can also increment the number on the same page either before or after updating your server.
When someone else visit that site the script again loads and send a request to your server so you can update the count on page but this time user does not click on like/dislike button so you dont update the record.
You may then show it as a pie chart to user on total visits to their site or page with division in people who liked it and people who did not report back (did not press the button)
If you are still wondering how you can create a button . Use CSS button generator to get one
You must first have a database where you can store various values.
Now, Whenever the user clicks the button, the value of the button stored in the database must be incremented. For this, you will need a backend language which connects you to SQL database.
So whenever the button has clicked the value of the likes in the database changes.
I want to detect and close a browser window. But before closing the browser page I need to update a SQL entry in an InUse table. There are a couple of unique situations added to this. When the EditPage.aspx opens for a (recordID record in a MstrTbl) I place an entry in the InUse table. I am tracking recno (autogenerated), userid, sessionid, recordID (MstrTbl), status, rectype, rwindicator, createdatetime, updatedatetime. I am using Session("gUserID") [all Session("variables")] when updating InUse table. The variables are fairly straight forward. But, there can be multiple users opening the same recordID, however, only 1st user in can edit. (Thus, rwindicator, Read/Write Indicator). In days of yore, you could control a vb6 app opening only once, but now in web world, a user can open multiple browsers (and records), and in this case need to be able to do so.
Okay, so if there is an InUse entry for this user, and this recordID, redirect the 2nd attempt to an error page (You can only open this record once) error, and back to the Default page for you.
Now a user is finished with a record, and can click Home (Site.Master Menu Item) or can simply click "X" in browser. I DO NOT want a "verify close" message (extra click), but where the InUse table had an [A]ctive status now needs updating time stamp and e[X]pired status. The solution can be java or jquery. I have tried several renditions of many attempts at "catching" the close with window. Using a hidden "btnCloseWindow" in a onbeforeunload functions seems to almost work a larger percent of the time, especially if I set an "alert" msg (which I do not want to do).
Code in the Window.close seems to never be able to update the InUse record. I've also tried timeout intervals. I have tried a dozen variations of different "solutions" (from other programmers attempts) but none seem reliable, if I get 2 or 3 users opening 3 or 4 of the same records, then closing them one at a time. I can create the InUse record. That's easy enough. But when a user closes a recordID, it will not update date/time stamp and status from [A]ctive to e[X]pire. I do not want to insert and delete records. This is an audit trail. But if the same userID opens the same recordID and it still shows [A]ctive, it will not allow the user to (in error) open it again.
The code in the EditPage.aspx.vb runs a Public Shared Sub (RecData.LockRec) in code behind, but then needs to run (RecData.CloseRec) when the "X" or "Home" Menu item is clicked.
In advance, any help is appreciated.
You can use window.onclose event but note you have a very small amount of time so your backend has to accept the posted event quickly. The browser will only wait for a short amount of time. So if you are doing anything complicated, accept the POST/GET from the client and then close the connection and then process the POST/GET.
I am working on an application with basic authentication functionality. When a user registers, I would like to display a javascript lightbox message containing a brief introduction to the application. Additionally, I would like to display notifications when a user logs in after a set time span (1 week, 1 month, etc). I'm not sure flash notifications will suffice as I plan on having slightly complex html in the messages, with forms/links/etc. I can think of a number of hacky ways to accomplish this, but none of them seem elegant and robust.
Any ideas?
You can just keep track of the login count and when it's their first login just activate the lightbox.
if current_user.sign_in_acount == 1
# render welcome lightbox
end
if current_user.created_at > 1.week.ago && not_notified?
# render notification lightbox
end
There won't really be an out of the box solution or anything and since you have two different types of scenarios for messages(time vs. login count) it's something you can just do for the small amount of times you are going to have to do it.
Maybe append a special parameter at the end of the URL after the user registers, and have JavaScript check for it? So after registration, send user to /whatever_page?just_registered, and have some JS code to check that.
if(window.location.search.test(/just_registered/)){
// pop up lightbox
}
Or you can just do a temporary cookie, set it, let Javascript check it, show the lightbox and delete it right away. You can do something similar with the display notification thing.
so, when a user visits the site for the first time i want to show a dialog box, and when the user clicks "x" or "hide" i want to hide it from that user forever.
this only works with cookies, right?
so, when the user clears his/her cookies he/she will see the dialog box again, next time they visit the site, i assume.
or is there a better/more common way to do this?
Can you store a property on the user? It can be false by default and when you click the 'x' you can make an AJAX call that sets it to true. Your dialog box could key off this property...
This way you wouldn't have to worry about the scenario where the user clears the cookies. Of course it will only work if you have user objects server side and it is storing extra data to overcome a very small problem, so it might not be goood practice. Just an idea.
No, nor should there be. Cookies are the only means for a site to retain information. Allowing a site to do anything more is a serious breach in security.
This is a fairly common approach to stored state.
Create a user_properties table add column "firstTimeDialog" (or isVirgin) as SMALLINT with default value of '1'. when user clicks box send AJAX call to server-side to change the value to 0. Load user properties with user information into the session on login and you a very simple way of checking to see if its a users first time.
Remember a users first time should be memorable, so be gentle.
Cookies are the correct answer to persistent state, but it's not a bulletproof solution.
What if a user visits your site on one computer, and then visits again from a different computer? They'll see the message twice. Usually in cases such as these I recommend rethinking your approach.
What is the purpose of the dialog?
Is there a reason the user shouldn't see it a second time?
Can it be placed elsewhere in the page for the same/better effect?
If you really want to be nasty with cookies, you can look at evercookie. But please only use your powers for good or for awesome.
Is there a Javascript library (preferably a jQuery plugin) or simple mechanism to check if a visitor is idle? For example, if the visitor to a webpage has been there more than 5 minutes only moving their mouse but not clicking any buttons or pressing any keys, then call a particular Javascript function.
It seems like I could just call setTimeout() for my desired idle time and then call clearTimeout() upon any mouse click or keyboard press by having something like $('body').click(clearTimeout(.... But I'm sure there are issues I don't want to have to figure out. The one thing I definitely don't want to have happen is for my site to think someone's been idle and they haven't really been. The other way around is ok.
Yes, very possible and there are a couple sites that use this (like banks and Mint) with great success. Take a look at these two blog posts:
http://www.erichynds.com/jquery/creating-a-mint-com-style-idle-logout-timer-using-jquery/
http://www.erichynds.com/jquery/a-new-and-improved-jquery-idle-timeout-plugin/
I have used this approach in the past with Admin pages within websites to a fair amount of success, especially after adding the modal dialog box informing users that the session was about to expire. This helps the user to feel like the web application/site is working with them to help.