Is it possible to check for new Gmail emails using Javascript? - javascript

I want to know whether or not I have a new email from Gmail, but I don't want to go to Gmail all the time.
Is it possible to use javascript to check if a new message has arrived?
I know it is possible using php classes, but I would like to do it javascript also.

I guess the first assumption should be the Gmail user should have got logged in to Gmail Website in the same browser and without any restarts of the machine, in other words gmail cookie should be alive and should say gmail that who is the logged in user.
Then you may write javascript to load http://mail.google.com in some hidden iframe and take it's document handle to explore the DOM of that page and find out any bold row in inbox table (this is very simple in saying but definately be complex in doing)

Nah, don't think so. Keeping in mind that the only way to do something like that would be AJAX-related => no possibility to access other sites but same as the JS on which the page resides on.

Yes and No. You can't do it with Javascript alone, but you can do it with Javascript if you can write some sort of proxy script to log into gmail and check for you - and then return that data in text/json/php/whatever...

Related

restrict site access if not authorized + DIV advice reflow

I hope to explain what I need in a clear way.
I have a site (which uses Javascript and Jquery) which should be accessed only by customers who are in good standing with payments, and I recognize them reading a server side database.
The mechanism works pretty well, but there is a minor problem which should be addressed.
After the validation check, if further site access must be blocked I use the following brutal code to show a message in a DIV (id=noway) and then stop any operation:
$("#noway").html("<p>You are not allowed to proceed since your payments are overdue</p>");
while 1{}
Problem: the DIV does not show anything until the browser's (mozilla) timeouts with a 'script in the page has stopped...continue..exit...' message.
It seems that Mozilla enters the infinite loop before of completing the DIV update. What can I do?
Besides this, is there any other more elegant way to block any further visitor activity?
Actually I thought to redirect the visitor to a different page with just the advice, but I would prefer not to do in this way, if possible.
Thanks
I think the best way to restrict site access is to do it server-side. Your page shell read the server-side database before it build any client-side output. So, if the user is not authorized, than the only page content shell be the message about the payment. And only if the user is OK, then the page outputs all the regular contents.

JAVASCRIPT AJAX - Prevent redirect?

$.ajax({url:"URL",success:function(result){
I have a webpage that accesses a certain URL and then extract certain elements of the webpage. However, in order to access that URL you have to be redirected to what is similar to a log in page (requires form submission) and then you have access to that link.
I want to prevent the redirection upon loading the URL. Is that possible?
If not, am I able to manually do the form submission using JAVASCRIPT? Via AJAX or any other resource.
EDIT: By manually saving the .html to my directory and accessing the page from my root folder, it works fluently.
Thank you!
Yes, it is possible. You need to stop the form submission and add your AJAX call. Like this:
$("form").submit(function(){
$.ajax({url:"URL",
success:function(result){
}
});
return false;
});
More information here.
If I understand your question, what you need to do is log the user into the external website programmatically beforehand. This is possible if the other site supports OAuth or something similar, but the specifics will depend on their API and what exactly you're trying to do. I can't tell you more than that without more information.
This assumes you're trying to include the other web page in an iFrame, or link directly to a page there, or something like that. If, on the other hand, you're trying to log in to the foreign website as the user, pull out some content, and mix it in with your own, then I suggest you change your approach. You'll probably run afoul of all kinds of anti-XSS security policies, either on the foreign website or in the browser depending on what you try to do. Or you'll have to ask your users to give you their password on another site, and they'll have to really trust you for that.
Generally speaking, if you want to interact with another website, the user's client should connect, log in, and receive content directly from the other server without you acting as an intermediary. I think perhaps you're asking the wrong question: Instead of "how can I do this without the user logging in," ask "how can I let the user connect and log in to another website without having to leave my page?"

Authenticate websites that are using my service through iframe

I have a service that I provide to different websites. For the website to use the service they implement a javascript that triggers a lightbox with a iframe in it.
The problem is I don't want any website to be able to use the service/iframe. Is there any way I can authenticate the websites using the iframe?
The way I see it, a random website can just take the javascript from a website using the service/iframe and implement it on it's own website.
Authenticating the actual users inside the iframe is no problem, there will be a login form and a register form. It's just the websites using the iframe I want to identify and authenticate.
Any suggestions is appriciated!
You could check document.referrer in JavaScript, and if the referring domain is not within a whitelist you provide (or the referrer is empty), don't display content at all.
But we all know how unreliable the referrer is, and it might exclude users even under wrong conditions.
Another way would only work it the sites embedding your iframe have server-side scripting and so can calculate some kind of hash - f.e. the hash of the current date and a secret keyword - and pass it as a GET parameter in your iframe URL. In your script, you check if the given value is the same as the hash you create with the same data - and display content based on that or not.
Using the current date could be problematic though if time zone settings for your server and the other site are different, and it might also break when a user calls the page around midnight. To prevent such problems, you could have the remote sites include the unix timestamp value used to create the hash as GET parameter as well - then you can check if that timestamp is not to old, and create the hash with that exact value. (Then other sites might try to just copy the parameters and use them on their page as well, but it will only work for a small time window.)

Link to pop of version of gmail message with javascript

I'm working on integrating gmail into an in house application so on a users dashboard they see the 10 newest emails with in their gmail account. I'm pulling in the emails using fsockopen and issue imap commands.
I've gotten the url to direct link to the message that looks something like this: https://mail.google.com/mail/u/0/#inbox/13e2b4235af0b71a
However in a pop up that still contains all of gmails regular interface. What I'd like to be able to do is from the link in our system pop up the gmail pop up version (if you click the "in new window" button within gmail). See below for the gmail pop up I'd like to direct link to.
edit: For those wondering. No grabbing the url from the bar and changing the thread id (th=) doesn't work.
Building it like this makes the application very dependent of Google. If they decide to work something else out as it works faster you need to rethink your hack.
I'd strongly recommend to use a more Generic approach.
Either using the GMAiL API: https://developers.google.com/google-apps/gmail/
Or using SMTP/IMAP/POP commands to the GMail server.
Good Luck!

How to get user feedback/bug reports on a Chrome Extension through itself?

I have created a simple Chrome Extension, but it's not easy for the users to contact me, beyond using the mailto function. I also don't have access to a server with which I can send AJAX calls to. Worst case scenario, I'll have the extension create a PasteBin, via its API of the error string and use mailto to email that to me, but that's not quite secure or elegant.
Is there a way I can create some sort of 'submit bug' function, easily within jQuery or HTML? Something like Chrome.SendFeedback() or Chrome.SubmitErrorLog() which gets sent directly to me, somehow?
Probably the easiest and quickest way to get feedback from users is going to be to embed a google doc form in an iframe in a page. You can insert it where you would have built a custom form to submit to an API.
http://www.youtube.com/watch?v=IzgaUOW6GIs
http://www.google.com/google-d-s/forms/

Categories