I've a TABLE, in a HTML5 document.
I've a view selector who hide/show some rows, using jQuery hide()
and show()
.
When user select the table (programmatically, using a 'select all' button, see below for the code), and then copy/paste into, for example, Word or Outlook email, the behaviour is different from FF and IE.
- FF: doesn't copy elements with
style='display: none;'
. It's desired and expected behaviour - IE: copy ALL, and paste ALL, so my visual 'trick' is then useless for IE users.
I add my selectAll
function. Simply expect a selector and select all the text inside it. It's something I copy/pasted from the jQuery forum.
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
// console.log(this, element);
if (typeof element == 'undefined') {
return;
}
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};
How can I select only visible elements ? Or... is there any other html/js trick?
BTW I'll downvote whoever will propose to:
change users
force users to change browser
ask me to render only visible cells and change server code