Ver Mensaje Individual
  #6 (permalink)  
Antiguo 01/06/2012, 16:13
Avatar de IsaBelM
IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: Copiar con rastro

ese código funciona en ff, chrome y safari, pero no en ie8 ni opera

de opera hay que olvidarse, ya que no acepta el evento oncopy

ie8 no admite (getSelection y selectAllChildren)

vamos a añadirle algunas cosillas
Cita:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript">
function Evento(elemento,nomevento,funcion) {
if (elemento.attachEvent)
{
var fnc=function(){
funcion.call(elemento,window.event);
}
elemento.attachEvent('on'+nomevento,fnc);
return true;
}
else
if (elemento.addEventListener)
{
elemento.addEventListener(nomevento,funcion,false) ;
return true;
}
else
return false;
}



function init() {
Evento(document.getElementById('control'), 'copy', function(event) {addLink(event);});
Evento(document.getElementById('bloque'), 'copy', function(event) {addLink(event);});
}


function addLink(ev) {
var body_element = document.getElementsByTagName('body')[0];
var selection;
if(window.getSelection) {
selection = window.getSelection();
var pagelink = "Información original de: &lt;a href='"+document.location.href+"'&gt;"+document.lo cation.href+"&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;";
} else {
selection = document.selection.createRange().text;
var pagelink = "Información original de: <a href='"+document.location.href+"'>"+document.locat ion.href+"</a><br /><br />";
}
var newdiv = document.createElement('div');
newdiv.id = 'temp';
newdiv.style.position='absolute';
newdiv.style.left='99px';
newdiv.innerHTML = pagelink + selection;
body_element.appendChild(newdiv);
if(window.getSelection) {
selection.selectAllChildren(newdiv);
} else {
document.getElementById('temp').focus();
window.clipboardData.setData('Text', document.getElementById('temp').innerHTML);
}
window.setTimeout(function() {
body_element.removeChild(newdiv);
},0);

if (document.all) ev.returnValue = false;
}
//document.oncopy = function() {addLink();};

window.onload = init;
</script>
</head>
<body>

<input type="text" value="un texto a copiar" id="control" />
<div id="bloque">
Suspendisse potenti. Praesent ut risus ligula, quis ultrices libero. Sed faucibus leo vitae tortor tincidunt eget pulvinar nulla suscipit. Vestibulum eget libero metus, sit amet iaculis ante. Curabitur sed ligula dolor. Aliquam erat volutpat. Cras sit amet ligula dolor, a eleifend sapien. Nam lobortis turpis nec nisl tempor sit amet malesuada diam luctus.
</div>

</body>
</html>
lo he probado y funciona en (ff, chrome, safari, ie8 y, aunque no lo he probado, ha de funcionar en ie9)
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}