Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Copia testo da textarea

    salve a tutti ragazzi...
    su http://www.dynamicdrive.com ho trovato un codice per copiare i dati contenuti in una textarea al click su un link ...
    l'indirizzo a cui si trova lo script è questo http://www.dynamicdrive.com/dynamici...selectform.htm

    il mio problema è che quello script nn funziona con firefox 2

    qualcuno saprebbe dirmi come variare il codice per farlo funzionare anche sul mio browser ?

    codice:
    style>
    .highlighttext{
    background-color:yellow;
    font-weight:bold;
    }
    </style>
    
    <script language="Javascript">
    <!--
    
    /*
    Select and Copy form element script- By Dynamicdrive.com
    For full source, Terms of service, and 100s DTHML scripts
    Visit http://www.dynamicdrive.com
    */
    
    //specify whether contents should be auto copied to clipboard (memory)
    //Applies only to IE 4+
    //0=no, 1=yes
    var copytoclip=1
    
    function HighlightAll(theField) {
    var tempval=eval("document."+theField)
    tempval.focus()
    tempval.select()
    if (document.all&&copytoclip==1){
    therange=tempval.createTextRange()
    therange.execCommand("Copy")
    window.status="Contents highlighted and copied to clipboard!"
    setTimeout("window.status=''",1800)
    }
    }
    //-->
    </script>
     
    
    
    ----
    
    
    <form name="test">
    Select All
    
    <textarea name="select1" rows=10 cols=35 >This is some text. This is some text. This is some text. This is some text.</textarea>
    </form>
    per comodità ho riportato il codice anche qua...

    grazie in anticipo

    kicko

  2. #2

  3. #3
    umh, no, nn ho capito niente

    nn sono esperto di javascript (a dire il vero nn c'è niente in cui sia esperto nel campo della programmazione) cmq,
    ho provato a inserire la funzione da te segnalata all'interno del mio script e richiamarla, ma senza risultato

    ecco il codice che ho provato ..
    codice:
    <script language="Javascript">
    <!--
    
    /*
    Select and Copy form element script- By Dynamicdrive.com
    For full source, Terms of service, and 100s DTHML scripts
    Visit http://www.dynamicdrive.com
    */
    
    //specify whether contents should be auto copied to clipboard (memory)
    //Applies only to IE 4+
    //0=no, 1=yes
    var copytoclip=1
    
    function HighlightAll(theField) {
    var tempval=eval("document."+theField)
    tempval.focus()
    tempval.select()
    if (document.all&&copytoclip==1){
    therange=tempval.createTextRange()
    therange=copy_clip(therange)
    //therange.execCommand("Copy")  -- -riga tolta dal codice...ad intuito :D
    window.status="Contents highlighted and copied to clipboard!"
    setTimeout("window.status=''",1800)
    }
    }
    
     
    // Copyright (C) krikkit - krikkit@gmx.net
    // --> http://www.krikkit.net/
    //
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License
    // as published by the Free Software Foundation; either version 2
    // of the License, or (at your option) any later version.
     
    function copy_clip(meintext)
    {
     if (window.clipboardData) 
       {
       
       // the IE-manier
       window.clipboardData.setData("Text", meintext);
       
       // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
       // het is mij echter onbekend vanaf welke versie dit precies werkt:
       }
       else if (window.netscape) 
       { 
       
       // dit is belangrijk maar staat nergens duidelijk vermeld:
       // you have to sign the code to enable this, or see notes below 
       netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
       
       // maak een interface naar het clipboard
       var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                     .createInstance(Components.interfaces.nsIClipboard);
       if (!clip) return;
       
       // maak een transferable
       var trans = Components.classes['@mozilla.org/widget/transferable;1']
                      .createInstance(Components.interfaces.nsITransferable);
       if (!trans) return;
       
       // specificeer wat voor soort data we op willen halen; text in dit geval
       trans.addDataFlavor('text/unicode');
       
       // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
       // nodig om het in op te slaan
       var str = new Object();
       var len = new Object();
       
       var str = Components.classes["@mozilla.org/supports-string;1"]
                    .createInstance(Components.interfaces.nsISupportsString);
       
       var copytext=meintext;
       
       str.data=copytext;
       
       trans.setTransferData("text/unicode",str,copytext.length*2);
       
       var clipid=Components.interfaces.nsIClipboard;
       
       if (!clip) return false;
       
       clip.setData(trans,null,clipid.kGlobalClipboard);
       
       }
       alert("Following info was copied to your clipboard:\n\n" + meintext);
       return false;
    }
    //-->
    </script>
    un esempio funzionante per usare questa funzione ?

    thx..
    kicko

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.