Connecting Tech Pros Worldwide Help | Site Map

copy filenaam in javascript function

  #1  
Old July 23rd, 2005, 10:35 PM
marcokrechting@zonnet.nl
Guest
 
Posts: n/a
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

  #2  
Old July 23rd, 2005, 11:25 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


marcokrechting@zonnet.nl wrote:[color=blue]
> 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?
>[/color]

function HN(link, tekst, clipdata) {
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}
...
}


JW



  #3  
Old July 23rd, 2005, 11:55 PM
Marco Krechting
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42e2c044$0$18956$dbd4d001@news.euronet.nl...[color=blue]
> marcokrechting@zonnet.nl wrote:[color=green]
> > 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?
> >[/color]
>
> function HN(link, tekst, clipdata) {
> // IE only
> if (window.clipboardData) {
> window.clipboardData.setData('text', clipdata);
> }
> ...
> }
>
>
> JW
>
>
>[/color]


  #4  
Old July 24th, 2005, 12:45 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Marco Krechting wrote:[color=blue]
> 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)}
> }
>[/color]

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



  #5  
Old July 24th, 2005, 02:35 PM
Marco Krechting
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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(\""+targe t+"\",\""+"http://nww."+li
nk+"\",\""+tekst+"\")'"+">"+tekst+L);
}

What went wrong?

Regards
MArco

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42e37c7a$0$69898$dbd4d001@news.euronet.nl...[color=blue]
> Marco Krechting wrote:[color=green]
> > 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
> >[/color][/color]
(wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+ "onclick='n(\""+target+"\"[color=blue][color=green]
> > ,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)}
> > }
> >[/color]
>
> No, because this will render the function useless to other browsers then[/color]
IE.[color=blue]
> 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
>
>
>[/color]


  #6  
Old July 24th, 2005, 02:45 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Marco Krechting wrote:[color=blue]
> 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(\""+targe t+"\",\""+"http://nww."+li
> nk+"\",\""+tekst+"\")'"+">"+tekst+L);
> }
>
> What went wrong?
>[/color]

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



  #7  
Old July 24th, 2005, 02:55 PM
Marco Krechting
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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(\""+targe t+"\",\""+"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


"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42e39a2b$0$87629$dbd4d001@news.euronet.nl...[color=blue]
> Marco Krechting wrote:[color=green]
> > 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";
> >
> >[/color][/color]
h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+"http://nww."+li[color=blue][color=green]
> > nk+"\",\""+tekst+"\")'"+">"+tekst+L);
> > }
> >
> > What went wrong?
> >[/color]
>
> 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
>
>
>[/color]


  #8  
Old July 24th, 2005, 04:15 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Marco Krechting wrote:[color=blue]
> Ok, tried again, the function is working but all text after where I
> run it on the age is missing.
>[/color]

Let's breakdown the function:
[color=blue]
> target=telt();[/color]

Is the telt() function correctly defined?
[color=blue]
> if (wi==1) {[/color]

Is wi defined as a global variable?
[color=blue]
> h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+
> "http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L);[/color]

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



  #9  
Old July 24th, 2005, 05:35 PM
Marco Krechting
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42e3adef$0$96032$dbd4b001@news.euronet.nl...[color=blue]
> Marco Krechting wrote:[color=green]
> > Ok, tried again, the function is working but all text after where I
> > run it on the age is missing.
> >[/color]
>
> Let's breakdown the function:
>[color=green]
> > target=telt();[/color]
>
> Is the telt() function correctly defined?
>[color=green]
> > if (wi==1) {[/color]
>
> Is wi defined as a global variable?
>[color=green]
> > h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+
> > "http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L);[/color]
>
> 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
>
>
>[/color]


  #10  
Old July 24th, 2005, 09:45 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Marco Krechting wrote:[color=blue]
> Everything was working fine until I entered the copy clipboard code.
>[/color]

So everything works fine again when you remove the clipboard code?
[color=blue]
> I tried to use Firefox JS console, but how do I check a complete
> html-file?
>[/color]

Just call the script in FireFox, then look into the JS console to see if
there are errors.


JW



  #11  
Old July 24th, 2005, 09:45 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Janwillem Borleffs wrote:[color=blue]
> Just call the script in FireFox, then look into the JS console to see
> if there are errors.
>[/color]

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



  #12  
Old July 24th, 2005, 10:05 PM
marcokrechting@zonnet.nl
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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

  #13  
Old July 24th, 2005, 10:25 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


marcokrechting@zonnet.nl wrote:[color=blue]
> 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]
>[/color]

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



  #14  
Old July 24th, 2005, 11:15 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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



  #15  
Old July 25th, 2005, 10:05 AM
marcokrechting@zonnet.nl
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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

  #16  
Old July 29th, 2005, 10:25 AM
Ankur Vedi
Guest
 
Posts: n/a

re: copy filenaam in javascript function


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

*** Sent via Developersdex http://www.developersdex.com ***
  #17  
Old July 29th, 2005, 08:55 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Ankur Vedi wrote:[color=blue]
> 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.
>[/color]

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



  #18  
Old July 31st, 2005, 02:45 AM
Ankur Vedi
Guest
 
Posts: n/a

re: copy filenaam in javascript function




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

*** Sent via Developersdex http://www.developersdex.com ***
  #19  
Old July 31st, 2005, 01:35 PM
Janwillem Borleffs
Guest
 
Posts: n/a

re: copy filenaam in javascript function


Ankur Vedi wrote:[color=blue]
> 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 .
>[/color]

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



Closed Thread