PDA

View Full Version : Another gmail feature..



krembo
10-08-2006, 10:24 PM
Hi all,
well, when there is an unanswered question there is only one place i come to..
This time I wonder about the "attach file" link in gmail.

It is interesting since clicking this link opens a hidden browse dialog box.

Basically, IE does not lets you set a value for file input field, and also does not allows you to initiate an "onclick();" event on it. It is a security matter.
If you try to do it and submit a form, the focus will be automatically set on the file input until you PRESS YOURSELF the browse button and select the file yourself.

Gmail comes over it. It lets you initiate the browse dialog from another link and then submit the form.

How do they do it?

btw: is it possible to change the label on the brose button from "browse.." to something else?

krembo
10-08-2006, 11:45 PM
Look at the following code

when pressing the "aaa" button it opens the browse dialog and sets the value of the real file field. but when the submit is pressed, it clears the file field and sets the focus on it. the second "File_2" field works fine.

So how does google do this? They lets you open the browse screen from a link and the explorer handles it just fine!




<form name="form" action="?action=save" method="post" encType="multipart/form-data">

<input name="File_1" type="file" >

<input name="file" type="text">

<input name="Submit" type="submit" class="button" value="aaa" onClick="document.form.File_1.click(); document.form.file.value=document.form.File_1.value; return false;">

<input name="submit" type="submit" class="button" value="Upload" onclick='document.form.File_1.disabled=true;'>

<input name="File_2" type="file" >

</form>

djr33
10-09-2006, 12:33 AM
gmail is insane. They have a chat built into it. And a heck of a lot of other stuff.
Have you even seen the source? There's nothing to it. It's a blank page.... just calling, with ajax, a heck of a lot of other pages.
Crazy.
Sorry, but not sure about this.
Maybe they just throw the focus to the browse button and fake the enter key?

tech_support
10-09-2006, 01:23 AM
gmail is insane. They have a chat built into it. And a heck of a lot of other stuff.
Have you even seen the source? There's nothing to it. It's a blank page.... just calling, with ajax, a heck of a lot of other pages.
Crazy.
Sorry, but not sure about this.
Maybe they just throw the focus to the browse button and fake the enter key?

Competition, Competition, Competition. G-Mail vs. Windows Live Mail :D

djr33
10-09-2006, 06:29 AM
Ew. Windows. Windows Live. It's like hotmail? Meh.

tech_support
10-09-2006, 06:34 AM
http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d

djr33
10-09-2006, 06:35 AM
Heh. A whole 2gb. That's what gmail started with. And now they're nearing 3.

windows is stupid. Probably IE only as well. Heh.

tech_support
10-09-2006, 06:38 AM
No, now it's FireFox compatiable (after 2 months!)

tech_support
10-09-2006, 06:38 AM
Forgot to mention: Invitation only. LOL

djr33
10-09-2006, 06:39 AM
I'm surprised.
Not bad, considering.

krembo
10-09-2006, 07:23 AM
ok kids, that's enough...
stop the ie vs opera vs firefox stupied wars. they don't bring us anywhere. they are just a bunch of browsers, nothing more, nothing less. for me it's the same if the NYT and the WashingtonPost has fought over their paper and printing technique.

Anyway, a good javascript to use on gmail pages is as follows:

javascript:window.clipboardData.setData('Text', window.frames[0].frames[3].document.body.innerHTML).

Since gmail builds their pages with ajax and JS this will bring you the output of the page after all the functions.
The idea is taken from the gmail skin:
http://persistent.info/archives/2004/10/05/gmail-skinning

And now back to the topic - does anyone has any idea how to use a link in order to open a browse dialog and to keep this dialog value ok so the form will submit it?

tech_support
10-09-2006, 07:27 AM
stop the ie vs opera vs firefox stupied wars. they don't bring us anywhere. they are just a bunch of browsers, nothing more, nothing less.

FireFox is more secure.
Internet Explorer is not.

FireFox is cool.
Internet Explorer is lame.

And since when did I mention Opera?

Edit: And check out Twey's sig - You might find more reasons to avoid IE there

djr33
10-09-2006, 07:58 AM
Heh. I'm with Tech on this.
However, yes, we're off topic.

Note: gmail was invitation only for the longest time, but now it lets you sign up, but only with a cell phone, which is kinda a pain.

And, sorry, I really have no idea about the browse question. Someone may in a bit. We'll see. I'm curious now.

tech_support
10-09-2006, 08:20 AM
btw: is it possible to change the label on the brose button from "browse.." to something else?

No you can't.

tech_support
10-09-2006, 08:24 AM
G-Mail doesn't require a cell phone number now.

Look at the source:



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gmail</title>
<link rel="alternate" type="application/atom+xml" title="Gmail Atom Feed" href="feed/atom" />
<script src="?view=page&amp;name=browser&amp;ver=o9cia6293i3x"></script>
</head>
<noscript><font face=arial>JavaScript must be enabled in order for you to use Gmail in standard view. However, it seems JavaScript is either disabled or not supported by your browser. To use standard view, enable JavaScript by changing your browser options, then <a href="">try again</a>. <p>To use Gmail's basic HTML view, which does not require JavaScript, <a href="?ui=html&zy=n">click here</a>.</p></font><p><font face=arial>If you want to view Gmail on a mobile phone or similar device <a href="?ui=mobile&zyp=n">click here</a>.</font></p></noscript>
<script>
<!--

var fs_time=(new Date()).getTime();




function wfs() {


try {
if (parent!=window && parent.wfs) {
return false;
}
}catch(e){}



if (top.location.href.indexOf('nocheckbrowser')!=-1) {
return true;
}




if (!is_browser_supported) {
top.location="?ui=html\x26zy=j";
return false;
}


var testcookie='jscookietest=valid';
document.cookie=testcookie;
if (document.cookie.indexOf(testcookie)==-1) {
top.location="html\x2Fnocookies.html";
return false;
}

document.cookie=testcookie+';expires=Thu, 01 Jan 1970 00:00:00 GMT';


var agt=navigator.userAgent.toLowerCase();


if (agt.indexOf('msie')!=-1 && document.all &&
agt.indexOf('opera')==-1 && agt.indexOf('mac')==-1) {


eval('var c=(agt.indexOf("msie 5")!=-1)?"Microsoft.XMLHTTP":"Msxml2.XMLHTTP";try{new ActiveXObject(c);}catch(e){top.location="html\x2Fnoactivex.html";}');
}


return true;

}

function lj() {

js.location.replace("?view=page\x26name=js\x26ver=bvgw6s37bz2k");

}




if (wfs()) {


document.write('<frameset onload=lj() rows="100%,*" border=0><frame name=main src="?view=page&amp;name=loading&amp;ver=h606kb6zstq1" frameborder=0 noresize scrolling=no><frame name=js src="?view=page&amp;name=loading&amp;ver=h606kb6zstq1" frameborder=0 noresize></frameset>');
}
-->
</script>
</html>


Can you believe that theres no DOCTYPE?

djr33
10-09-2006, 08:42 AM
Ha. Gmail is better than a doctype. :p

krembo
10-09-2006, 09:04 AM
Any JavaScript guru around?

tech_support
10-09-2006, 09:31 AM
Try this:



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Attach File&nbsp; Remove</title>
<script>
function toggleElement(elementId,mode) {

element = document.getElementById(elementId)
element.style.display = mode
}
</script>
</head>

<body>
<div id="attach">
<a href="javascript:toggleElement('browseFile','block');javascript:toggleElement('removeLink','block')">Attach File</a><br />
<input type="file" style="display:none" id="browseFile"><span id="removeLink" style="display:none"> <a href="javascript:toggleElement('browseFile','none');toggleElement('removeLink','none')">Remove</a></span>

</div></body>

</html>

krembo
10-09-2006, 09:58 AM
tech_support, if this was the answer, i would never ask the question :-)
I don't want to show and hide a div. this is a trick for beginners.
What google does is that they launch the browse dialog box when pressing the link. This can be done by using the

onclick="FileFieldID.click();"


but again, the value it stores is erased immidiently as you press the submit form button since the user did not manually clicked the button himself.

Google has managed to sort this problem somehow, and the question is - HOW??!

tech_support
10-09-2006, 10:03 AM
I don't know what you mean :confused:

krembo
10-09-2006, 07:29 PM
I warned you this is a problem for pros...

Look at the attached file - to make things short:

There is a Text link which opens the Browse dialog box

djr33
10-09-2006, 08:02 PM
5520 unread messages in your inbox? Impressive... heh.

And, just for the record, I'm not sure of the answer, though I did understand the question, as I said before.

Perhaps javascript can help? I mean.... you have the value there, then it dissapears when sent.... so grab it before it dissapears.... fairly simple, I'd think, but I'm probably missing something.

krembo
10-09-2006, 09:36 PM
Yes you are missing something.
Im not interested in the value but in the uploaded file. The value which disappears is in the real <input type=file> but since it did not get there with a "real user click" it will not let you subit the form and upload the file.

blm126
10-09-2006, 11:29 PM
http://sheetaljain.com/blog/2005/10/gmail-file-attachment-secret-inputfile.html

I did a google search for "file input Attach File Gmail (http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=file+input+Attach+File+Gmail&btnG=Search)" 5th result

tech_support
10-10-2006, 03:37 AM
I warned you this is a problem for pros...

Please don't be so rude. I'm trying to help and your saying it's only for pro's.

djr33
10-10-2006, 03:38 AM
Pros would have searched google, for that matter. :p

tech_support
10-10-2006, 03:41 AM
Oh yes, Google. What about Windows Live Search? Ever tried that? Awful.

djr33
10-10-2006, 04:17 AM
ha.
:p
//amusing, though we are actually off topic.

tech_support
10-10-2006, 04:20 AM
Ah yes. Be on topic.

krembo
10-11-2006, 01:04 PM
blm126 - You are a google professional! Well, this is one good title you earned :D

I did search google for the answer but could not find it! Thanks alot!!!
tech_support - if you think that I was rude, I want to apologize..Didn't mean to :)

tech_support
10-12-2006, 05:31 AM
Ah it's ok. Doesn't matter really.