Dave819
Dave819

Reputation: 601

I need to improve a function that selects all text in a table

I have this function which selects all text in an element (table in this case)

function SelectText(element) {

    var text = document.getElementById(element);
        var range = document.body.createTextRange();
        range.moveToElementText(text);

        range.select(); 
}

I need help making it do the following

  1. Ignore some words that I specify (ie. not select them)
  2. Automatically put the selected text in clipboard

Upvotes: 0

Views: 62

Answers (2)

Sam
Sam

Reputation: 2201

range.execCommand("Copy");

That will put your text in the clipboard.

I don't think ignoring words is possible. You could potentially remove the text before copying.

Upvotes: 1

Tim Down
Tim Down

Reputation: 324587

That code is IE only, and IE doesn't support multiple selections. The only major browser that does is Firefox, so you may want to abandon that idea. Also, it's not generally possible to copy content to the clipboard with JavaScript, although there are Flash-based hacks like Zeroclipboard (http://code.google.com/p/zeroclipboard) that do this.

Upvotes: 2

Related Questions