I made a function that can take a an address from url and return its latlng and show a marker on the address. Is there a javascript function that can write the latlng to clipboard. Thanks.
-
what you have done so far? show us the code – xkeshav Jul 12 '12 at 07:10
2 Answers
No, there is no standard mechanism for JavaScript access to the clipboard (yet). There are various non-standard mechanisms, like Flash (zeroclipboard and the like), but of course they require Flash.

- 1,031,962
- 187
- 1,923
- 1,875
-
Agree - pragmatically, this task is going to require Flash for a while. – Ben Parsons Jul 12 '12 at 08:15
-
@T.J. Crowder: +1 I think your answer suits better to the question than the mine. He's just asking if is there a javascript function which can do things, actually :) – A_nto2 Jul 12 '12 at 09:30
As T.J. Crowder said in his answer and afaicr, there isn't a javascript function which can access to the clipboard.
Anyway, if you are under Windows, you could try to combine your javascript with WSH
(Windows Script Host) script and passing the latlng to the clipboard from such as script.
Be aware you can script a WSH file using both javascript(JScript, the Microsoft Javascript flavour, it's identical to javascript, only the name changes) and VBscript in the same file, if you need. So you can reutilize online VBscripts which perform the access to the clipboard, and passing your variable value obtained in JScript.
Some URLs I found, just to point out the question (try to search better, even VBscript or WSH tutorials):
http://www.memosoup.com/20100126/using-the-clipboard-in-wsh.html
http://www.codeproject.com/Articles/33702/WSH-Clipboard-Access
http://nerds-central.blogspot.it/2007/01/using-jscript-to-paste-text-into.html
You could store the latlng values in a Cookie
, and then read it from a WSH
script which will perform the copy to the clipboard. In another way, you could write a simple console .exe
program which perform the same task. You can launch them from the server side language, or from javascript, I guess.
If you're developing under Unix, you could try to search for informations about the possibility to make the above things from Unix shell script
or in Unix programming
.
-
1Suggesting a Windows specific technology to a JS question isn't very helpful if you ask me. – Jørgen R Jul 12 '12 at 07:43
-
That isn't possible I'm afraid. http://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-java-script – Jørgen R Jul 12 '12 at 07:52
-
How? JS is running sandboxed inside the browser and isn't allowed to execute arbitrary code on the computer. – Jørgen R Jul 12 '12 at 08:02
-
I was talking about other, non Windows systems. It's ok though. I just wanted to point out that it isn't a viable solution if OP wants to support other OSes. – Jørgen R Jul 12 '12 at 08:32
-
@jurgemaister: You could copy to the clipboard by calling a WSH script from server side language, or from javascript and passing the latlng values? Or Simply setting a cookie, and read it from a WSH script and so copy to the clipboard. It seems to be a bit tricky,I know, but could be a way. – A_nto2 Jul 12 '12 at 08:39