copy and paste from clipboard using javascript

Discussion in 'JavaScript' started by yasser251, Jun 3, 2010.

  1. #1
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function copyit(theField) {
    var selectedText = document.selection;
    if (selectedText.type == 'Text') {
    var newRange = selectedText.createRange();
    theField.focus();
    theField.value = newRange.text;
    } else {
    alert('select a text in the page and then press this button');
    }
    }
    // End -->
    </script>
    </HEAD>

    <body>

    <form name="it">

    <p>This script allows you to select text on a web page and then copy it into a text box. Neat! yasser_251@yahoo.com</p>
    <div align="center">

    <input onclick="copyit(this.form.select1)" type="button" value="Press to copy the highlighted text" name="btnCopy" return true">

    <p>
    <textarea name="select1" rows="4" cols="45"></textarea>
    </div>
    </form>


    this script copy text to clipboard and paste it again into a text area in the web page by only on click.
    what i need to do is:
    copy the text selected into the clipboard and then paste it at the end of URL page link while open a new web browser, example
    http://www.domain.com/(paste text here)

    i did that before, but by dealation mistake i removed that script from the server, and i try a lot to make puzzle to get it work again, but i failed.

    i only can remember that i was made a simple puzzle with this line.

    <input onclick="copyit(this.form.select1)" type="button" value="Press to copy the highlighted text" name="btnCopy" return true">

    yes, only this line need to be edited i think that, not sure..

    try to use this line a see the action
    <input onclick="window.open('http://www.yahoo.com') + copyit(this.form.select1)" type="button" value="test">

    with this code the script will open yahoo in new page but script did not paste (copied text) at the end of http://www.yahoo.com(text not copied here)

    text will also copied in the text area in the same page.

    i hope i can explane my problem, and also i hope some one can help me in that issue..

    Thanks a lot for every one try to help me..
    Regards
    Zahar
     
    yasser251, Jun 3, 2010 IP