How to create a link that has a textbox "auto-filled"? - javascript

How do I create a link that when the user clicks, it will bring him to the Google page as shown below (with the To field completed):
Right now, what I've managed is to simply link him to https://mail.google.com/mail/#compose and this is what he will see:
Similarly, is there a way to achieve this on hotmail as well?

https://mail.google.com/mail/?view=cm&tf=1&to=someone#gmail.com&fs=1
This shows the composition screen. To get the whole gmail interface, remove &tf=1.
If you also want to preset a subject, just add &su=YourSubject to the query string

The data is sended by POST, I think. Try to trace the HTTP Header when clicking on the link that redirects to the already filled page, with the Firefox Addon "Live HTTP Headers" for example. If the third line starts with POST, look at the last line before "HTTP/1.1 200 OK", this is the sended POST data. You will probably find the auto filled mail adress there. If so, you can do a javascript POST request to the given URL: http://www.bennyn.de/programmierung/javascript/http-post-request-mit-javascript.html, or you can use a framework like jQuery.

This does not answer your question but if you are to request a person to send an email then it is best to use the mailto: in your links so that it uses the computers default mail service. I am unaware if this uses web-based mail but it will open up the computers default mailing program (And it stops you from having to account for every different email service).
And I tested Dennis's answer, and it does work for me. What do you mean by 'It ain't working', any error messages? anything that can help solve the issue?

Related

How can I background a mailto in Javascript?

I want to create a form that works with ‘button id=“this” onclick=“sendToME”’ and I do not have my email reavealed (unless they open the console) at the moment of sending the data from the form.
The proper way to achieve your goal is to make an api endpoint (the button should point here), which are handle the process of email sending.

Is it possible to prevent that a popup be opened directly as opposed to being opened by Javascript?

The application I'm working on relies on many popups. Those popups rely themselves on query strings. If someone can just type the url in the browser address bar, the page will throw an error as the query strings values are dynamically constructed.
function myFunction(id)
{
window.open("mypopup.aspx?id=" + id);
}
Is there a why to prevent the page from displaying if the requester of the page is not a Javascript? If someone type something like:
https://mycompanyname.com/path/mypopup.aspx
It shouldn't let the user do so. Or, at least check whether the requester is not javascript so I can display a message or redirect the user to a different page? Otherwise, without all those pieces of data needed to construct a request, the page will throw an exception.
Thanks for helping.
Validate the query string directly in myPopup.aspx, if something is missing just redirect or display a message.
Use the Request.QueryString collection to validate in myPopup.aspx.
There is no easy way to validate if the request came from javascript as far as I know. You could try creating a token to validate that the sender is the one you expect, but if you only need to validate the parameters, no need to worry about who is sending the request.
The page cannot differentiate how it was requested, if both requests come from a same browser.
However, you can include in query string to differentiate them.
For example,
window.open("mypopup.aspx?request=javascript&id=" + id);
If a user intentionally type in https://mycompanyname.com/path/mypopup.aspx?request=javascript, so be it. I won't worry about it.
Popups are browser windows too. So it will be tricky to check if the window requesting the page is normal window or popup.
You should restrict the users to see on what url the popup is being opened you can hide the address bar. So user can not copy or know the what's in the url.
window.open('/pageaddress.html','winname','directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=350');
Setup a token based validation. Make request to server(Ajax request) to get a random token(with one time validation mechanism and expire it), You can send the token in the query string and validate it on server if it's same issued token. Identify if the requested page have valid token(popup) otherwise deny the request or show error message. Think of how captcha works, you just need to do it programmatically.
Though it's also not the best solution as token information can be sniffed through network traffic tracker tools like fiddler but it's will work to prevent manual requests.

Facebook Commenst Box: can't add comments

I'm adding Facebook-commenting functionality to the site. It doesn't have domain name yet, so I'm accesing it by numeric IP.
I've succeeded in showing the box with the comment adding form, and I can log in and send something. But after each send the comment just is not added.
Is numeric address a source of the problem?
I had the same situation and when I used it on a real domain, it works. Somehow it does not work on ip server. Better you move the site to live domain and try again and it should work :)

"Undefined" appearing sometimes in the URL of my ASP.NET application (somehow google related?)

Some users repeatedly run into a very mysterious problem when using my web application.
In the middle of using it, they'll click a button or link that takes them to another page, but there will be a "page not found" error, because the URL is something like:
http://www.correctwebsitename.com/undefined
I thought it might be a javascript bug in my app: a redirect done by choosing a page name (maybe with some parameters) where one of the values is bad, resulting in the page name = "undefined". But there is no such code in my app anywhere, and this happens on many different pages, seemingly at random.
The one thing that seems to make it happen more often is if the user logged in originally by clicking a link in an email message in gmail. But a user who cut and pasted the link URL into a browser window said it still happened. Googling around reveals some hints that some kind of Google redirecting or caching is happening behind the scenes.
Any ideas?
Edit:
I'm not getting responses from anyone familiar with how gmail links etc work, does anyone know what SO tags google experts "hang around in"?
Edit 2:
Awarding bounty to top answer for useful info and temporary workaround idea, but still interested in real solution to the problem, so not accepting workaround as solution.
I believe you are right about gmail doing something with the links. See the gmail image below:
Non-standard header fields are conventionally marked by prefixing the field name with X-
Its probably behaving like... oh well, Google, and inspecting everything.
To stop google search from tracking my clicks i had to create a userscript to rewrite one of their functions:
rwt = function(){};
Maybe you can try something similar for gmail.
What is rwt?
rwt() is a javascript function from google search that rewrites the links to track which site you have visited.
for example, searching for "greasemonkey" showed the mozilla addons page as the first result. clicking on it opened
https://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCUQFjAA&url=https%3A%2F%2Faddons.mozilla.org%2Fpt-BR%2Ffirefox%2Faddon%2Fgreasemonkey%2F&ei=iWNtUIXjIoyQ8wTxv4DQAQ&usg=AFQjCNEO9EJcHp9rAmKyD_XZF2Bt6hs_YQ&sig2=P19xVUsD-Q1G_9AiUBP3PQ
and then redirected to
https://addons.mozilla.org/pt-BR/firefox/addon/greasemonkey/
The image above and the rwt() case is just to show you that there is a great chance that gmail is changing the links, so this could be related to your problem.
Since there is nothing you can do at gmail's side, maybe you could fix it on your server, by redirecting http://www.correctwebsitename.com/undefined to http://www.correctwebsitename.com or any other page that you'd like your users to see.
So, be it from gmail or any other referer, every time a client lands on http://www.correctwebsitename.com/undefined redirect him to another page.
so maybe I can figure out how to just send them back to the page they
came from
ASP
if not request.UrlReferrer is nothing then
response.redirect (request.UrlReferrer.tostring)
end if
JS (for this to work, you would have to actually create a page called undefined)
if (window.location.href.toLowerCase().indexOf('undefined') > -1) {
// this works
window.location.href = document.referrer;
// this works too (uncomment to enable)
// history.back();
}
remember that if the user directly typed the url or used the link from favorites there wont be no referrer
I would suggest you to check the below things in your application.
Is there any code in your application, apart from what you own ?
there can be injected code by third party applications, like for ex "AddThis" adds an extra #parameter to your url sometimes, in your case its clear that a javascript is trying to playaround with the location.href as "undefined" is something which many js developers will come across.
by adding an # will help do cross site communication, some bug might also be causing an issue here.
Do a complete search in your code for "location.href" and see if you have used it anywhere.
Sometimes third party addons on the browser too might cause this issue
hope these would help you narrow down to your problem.
if you are not able to trace out the issue anywhere, i would suggest you to override 404 functionality on your webserver and implement the solution using Referrer.

Javascript to input searches on multiple websites and take a screenshot

I am trying to automate the querying of names on 2 different websites. For each website I have to enter in the same name and take a screenshot of the results.I don't know how to approach this project. Is it possible to automate this with a javascript? Thank you for any input.
Website links are below:
[1] http://exclusions.oig.hhs.gov/search.aspx
[2] http://www.health.ny.gov/professionals/doctors/conduct/license_lookup.htm
You should be able to accomplish this with PhantomJS relatively easily. Check out the examples page - you'll probably want to use code evaluation to fill out and submit your forms, after which you can render the page to an image file.
You actually do this is one step: send a POST requests to the information you need. For the first example, you would send these POST data:
__VIEWSTATE=dDwtNzQ5MzEyMDI3Ozs%2BHWC8LXZfQQTCTJWtmudNLStjn%2Fk%3D&txtLastName1=test&txtFirstName1=&txtBusinessName1=&txtLastName2=&txtFirstName2=&txtBusinessName2=&txtLastName3=&txtFirstName3=&txtBusinessName3=&txtLastName4=&txtFirstName4=&txtBusinessName4=&txtLastName5=&txtFirstName5=&txtBusinessName5=&cmdSubmit=Search
So you can use PhantomJS, as suggested, with a POST request and take a screenshot. Or you can use a web service to create the screenshots. Unfortunately, very few allow POST requests with custom POST data. Browshot (see API) lets you send POST data and use a custom Referer. So your screenshot requests would include (after you encode the POST data):
url=http://exclusions.oig.hhs.gov/search.aspx&referer=http://exclusions.oig.hhs.gov/search.aspx&post_data=__VIEWSTATE%3DdDwtNzQ5MzEyMDI3Ozs%252BHWC8LXZfQQTCTJWtmudNLStjn%252Fk%253D%26txtLastName1%3Dtest%26txtFirstName1%3D%26txtBusinessName1%3D%26txtLastName2%3D%26txtFirstName2%3D%26txtBusinessName2%3D%26txtLastName3%3D%26txtFirstName3%3D%26txtBusinessName3%3D%26txtLastName4%3D%26txtFirstName4%3D%26txtBusinessName4%3D%26txtLastName5%3D%26txtFirstName5%3D%26txtBusinessName5%3D%26cmdSubmit%3DSearch
I have tested it, and do get a screenshot of the results, like if I filled out the form and submitted it.

Categories