copy filenaam in javascript function
|
|
Thread rating:  |
marcokrechting@zonnet.nl - 23 Jul 2005 13:02 GMT Hi All,
I have a rather complicated problem. I use following function to display a hyperlink:
a="<"+"a href='"; b3="<"+"a href='http://nww."; L="</"+'a><br>';
function h(a){document.writeln(a)} function HN(link,tekst){target=telt();if (wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\",\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)}
Now I need an additional option to store a filename like: function HN(link,tekst, filename)
The function HN should be rearranged that when I click this hyperlink the filename gets stored to the clipboard, so I can release it with Ctrl-V.
For Example: HN('nix.nothing.int/WHERE/2005','My Hyperlink','NIX.NOTHING.TEXT.20050723.')
Where the last part: NIX.NOTHING.TEXT.20050723. is the part which needs to be copied to the clipboard.
Anyone knows how I should change the function HN to get this done? Or is it not possible?
Regards
Marco The Netherlands
Janwillem Borleffs - 23 Jul 2005 23:10 GMT > The function HN should be rearranged that when I click this hyperlink > the filename gets stored to the clipboard, so I can release it with [quoted text clipped - 9 lines] > Anyone knows how I should change the function HN to get this done? > Or is it not possible? function HN(link, tekst, clipdata) { // IE only if (window.clipboardData) { window.clipboardData.setData('text', clipdata); } ... }
JW
Marco Krechting - 23 Jul 2005 23:46 GMT Janwillem,
Thanks for the help but where exactly should I add this piece of code? Like this?
function HN(link,tekst,clipdata){ // IE only if (window.clipboardData) { window.clipboardData.setData('text', clipdata); {target=telt();if (wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\" ,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)} }
Marco
> > The function HN should be rearranged that when I click this hyperlink > > the filename gets stored to the clipboard, so I can release it with [quoted text clipped - 19 lines] > > JW Janwillem Borleffs - 24 Jul 2005 12:33 GMT > Janwillem, > [quoted text clipped - 9 lines] > ,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)} > } No, because this will render the function useless to other browsers then IE. The only part that needs to be excluded from other browsers is the window.clipboardData bit. Take the code I have shown you before and insert the original function body below it:
function HN(link,tekst,clipdata){ // IE only if (window.clipboardData) { window.clipboardData.setData('text', clipdata); }
// Original function body target=telt();
// I assume wi is defined somewhere? if (wi==1) { target="_top"; } h(....); }
JW
Marco Krechting - 24 Jul 2005 14:30 GMT I tried the code listed below but it doesn't work:
function HN(link,tekst,clipdata){ // IE only if (window.clipboardData) { window.clipboardData.setData('text', clipdata); }
// Original function body {target=telt(); if (wi==1)target="_top";
h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\",\""+"http://nww."+li nk+"\",\""+tekst+"\")'"+">"+tekst+L); }
What went wrong?
Regards MArco
> > Janwillem, > > [quoted text clipped - 6 lines] > > window.clipboardData.setData('text', clipdata); > > {target=telt();if (wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\"
> > ,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)} > > } [quoted text clipped - 21 lines] > > JW Janwillem Borleffs - 24 Jul 2005 14:39 GMT > I tried the code listed below but it doesn't work: > [quoted text clipped - 13 lines] > > What went wrong? You added an erroneous opening brace:
{target=telt();
This should be:
target=telt();
Please look again closely to the example in my previous reply.
JW
Marco Krechting - 24 Jul 2005 14:50 GMT Ok, tried again, the function is working but all text after where I run it on the age is missing.
function HN(link,tekst,clipdata){ // IE only if (window.clipboardData) { window.clipboardData.setData('text', clipdata); }
// Original function body target=telt();
// I assume wi is defined somewhere? if (wi==1) { target="_top"; }
h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\",\""+"http://nww."+li nk+"\",\""+tekst+"\")'"+">"+tekst+L); }
HN('nix.com/2005/','My Daily Report','DAILY.REPORT.') ------> after this all code on the page is missing....
Marco
> > I tried the code listed below but it doesn't work: > > [quoted text clipped - 7 lines] > > {target=telt(); > > if (wi==1)target="_top"; h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\",\""+"http://nww."+li
> > nk+"\",\""+tekst+"\")'"+">"+tekst+L); > > } [quoted text clipped - 12 lines] > > JW Janwillem Borleffs - 24 Jul 2005 16:04 GMT > Ok, tried again, the function is working but all text after where I > run it on the age is missing. Let's breakdown the function:
> target=telt(); Is the telt() function correctly defined?
> if (wi==1) { Is wi defined as a global variable?
> h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+target+"\",\""+ > "http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L); Is the h() function correctly defined?
Are the following variables globally defined:
b3 tag L
Note that when variables not defined globally, should be defined in the function itself.
BTW, a good JS debugging tool is FireFox's javascript console.
JW
Marco Krechting - 24 Jul 2005 17:28 GMT Everything was working fine until I entered the copy clipboard code.
b3 = "<"+"a href='http://nww."; tag = "target='" L = "</"+'a><br>'; tel=0;function telt(){tel++;return tel};
I tried to use Firefox JS console, but how do I check a complete html-file?
Marco
> > Ok, tried again, the function is working but all text after where I > > run it on the age is missing. [quoted text clipped - 26 lines] > > JW Janwillem Borleffs - 24 Jul 2005 21:38 GMT > Everything was working fine until I entered the copy clipboard code. So everything works fine again when you remove the clipboard code?
> I tried to use Firefox JS console, but how do I check a complete > html-file? Just call the script in FireFox, then look into the JS console to see if there are errors.
JW
Janwillem Borleffs - 24 Jul 2005 21:41 GMT > Just call the script in FireFox, then look into the JS console to see > if there are errors. That is: call the page that includes the script in FireFox. If this doesn't bring up errors, then post an URL where the page can be viewed somewhere.
JW
marcokrechting@zonnet.nl - 24 Jul 2005 22:02 GMT Got three time the error: Dialog has no properties
and this one (I don't know what it means): Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line 638" data: no]
Marco
Janwillem Borleffs - 24 Jul 2005 22:17 GMT > Got three time the error: Dialog has no properties > [quoted text clipped - 4 lines] > chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line > 638" data: no] Do you programmatically create a popup window anywhere in your code? Does the script work when you remove the window.clipboardData bit?
The following code works without any problems in both IE and FireFox:
<html> <head> <title> New Document </title> <script type="text/javascript"> function test(text, clipdata) { if (window.clipboardData) { window.clipboardData.setData('text', clipdata); } document.write(text); } </script> </head>
<body> <script>test('Hello', 'World');</script> </body> </html>
Are you doing something simular or are you calling the HN function when the page is already done loading? In that case it's important that the h() function does not use document.write as this will wipe out the initial page including the scripts.
JW
Janwillem Borleffs - 24 Jul 2005 23:12 GMT The problem appears to be that the window.clipboardData.setData() function expects a string as the second argument and sometimes it's an integer.
Changing the call into:
if (window.clipboardData) { window.clipboardData.setData('text', '' + clipdata); }
will fix this...
JW
marcokrechting@zonnet.nl - 25 Jul 2005 10:01 GMT With this new code it now works fine:
function setClip(clipdata) { if (window.clipboardData) { window.clipboardData.setData('text', clipdata); } }
function HN(link,tekst,clipdata) { target=telt(); if (wi==1) { target="_top"; }
text2write = b3 + link + "'" + tag + target + "'"; text2write += "onclick='setClip(\"" + clipdata + "\");"; text2write += "n(\""+target+"\",\""+"http://www."+link+"\",\""+tekst+"\")'"; text2write += ">" + tekst + L; h(text2write); }
thanks a lot JW
MArco
Ankur Vedi - 29 Jul 2005 10:21 GMT Hi ,
This is a very intersting discussion thats going on. Now i tried doing absolutely the same thing in FireFox and it just did not work. There are 2 things that i tried
1) <script language="javascript" type="text/javascript">
function sendToClipboard(s){
window.clipboardData.setData('text', "123456789"); }
When i do this, i get the follwoing error in the JavaScript Console of Firefox -:
Error: window.clipboardData has no properties Source File: file:///C:/Ankur/Test/CopyTest.html Line: 15
2) And when i try to do something like this -:
<script language="javascript" type="text/javascript">
function sendToClipboard(s){
if( window.clipboardData && clipboardData.setData ){ alert("In the IF loop with s being " + s); window.clipboardData.setData("Text", s); }else{
alert("In the ELSE loop "); }
} </script>
In this case , it does not even go to the IF loop. It just goes to the else and comes out.
Any advise will be really appreciated. Thanks in advance
Janwillem Borleffs - 29 Jul 2005 20:43 GMT > This is a very intersting discussion thats going on. Now i tried doing > absolutely the same thing in FireFox and it just did not work. That's the whole idea of the condition; FireFox does not support window.clipboardData, so you cannot populate data to the clipboard using JS with this browser...
JW
Ankur Vedi - 31 Jul 2005 02:41 GMT Hi JW,
Thanks a bunch for your reply and clearing that doubt.
Now if you are saying that window.clipboardData cannot be used with Firefox, then can you please advise as to how may i achieve the same functionality in Firefox, ie copying some data on the browser so that i can paste it later somewhere using Ctrl V .
Thanks Again Ankur
Janwillem Borleffs - 31 Jul 2005 13:22 GMT > Now if you are saying that window.clipboardData cannot be used with > Firefox, then can you please advise as to how may i achieve the same > functionality in Firefox, ie copying some data on the browser so that > i can paste it later somewhere using Ctrl V . I don't think it is possible in FireFox without a special extension like the one found at: http://www.gratisdei.com/copytoclip.xpi
JW
|
|
|