JavaScript Special paste with javascript paste special with format vba,paste special with multiply,paste

I need to interpret text copied from emails. Currently, the users copy the text of the email and paste it into an HTML text area. I already have a 90% solution, but here is one case that is stumping me. The data is stored in a table in the email. Here is one row of that data, which could easily have 50 rows or more, in a similar format:

<tr>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">WI</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">BARABOO 53913</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">8:00</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">VAN</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">WI</span><o:p></o:p></p>
</td>
<td valign=3D"top" style=3D"background:white;padding:0in 0in 0in 0in">
<p class=3D"MsoNormal"><span style=3D"color:black">8/29/2015</span><o:p></o:p></p>
</td>
</tr>

This is an example of the sort of things I have to accomodate, although I actually want to accomodate a lot more.

When the user pastes that row, it turns into this:

WI


BARABOO 53913


8:00


VAN


WI


8/29/2015

Keep in mind that I am receiving many rows, so they all get run together. The number, order, and format of the columns are completely inconsistent, sometimes even within the same document.

If I could get this, I can use my already existing code to parse it:

WI BARABOO 53913 8:00 VAN WI 8/29/2015

But I have pretty much nothing to work with. If I had the raw HTML, I could parse it safely (It is never displayed), but I can't get it. Does anyone know how I can get this as raw HTML or some other coherent format? I doubt if it matters, but in most cases, the source of the copy will be MS Outlook.

edit: the whole goal is to make this machine-parsable. I don't need help with the parsing, I have that covered. I just need something useful to parse.

Answer:1

You can get the pasted HTML maintained if you replace your text area with a "contentEditable" element, such as a <div>. Try this for example, it will alert the html "source" you paste into it:

var paste = document.getElementById('paste');
paste.onpaste = function() { setTimeout(function() { alert(paste.innerHTML); }, 1); };
#paste {
  width:200px;
  height:60px;
  border: 2px solid blue;
}
<div id="paste" contentEditable="true"></div>
Answer:2

It looks like the paste event, for Chrome and Firefox, may have a clipboardData property of type DataTransfer. That has a getData method that takes a content type, so you may be able to do this to check if the content is HTML:

textArea.addEventListener('paste', function (e) {
  var html = e.clipboardData && e.clipboardData.getData('text/html');
  if (html) {
    // handle HTML table logic
  }
});

Update:

Interestingly, IE has a beforepaste event which looks like it has a similar clipboardData object, so maybe you can handle that browser using this technique.

Answer:3

I want to know how to execute some function when I close my browser... so the detail is I making website that going to sell items and the scenario is user login to my website and then they select some ...

I want to know how to execute some function when I close my browser... so the detail is I making website that going to sell items and the scenario is user login to my website and then they select some ...

  1. execute a function after some time javascript
  2. execute a function after some time python
  3. execute a function after some time java

I'm using bootstrap-select and everything is working fine,until options of my select tag are filled with data from php file. I have seen each post on this topic, but there is no answer. So here is an ...

I'm using bootstrap-select and everything is working fine,until options of my select tag are filled with data from php file. I have seen each post on this topic, but there is no answer. So here is an ...

  1. bootstrap select with search
  2. bootstrap select with checkboxes
  3. bootstrap select with images
  4. bootstrap select with label
  5. bootstrap select with text input
  6. bootstrap select with placeholder
  7. bootstrap select with icon
  8. bootstrap select with input
  9. bootstrap select with search box
  10. bootstrap select with search example
  11. bootstrap select with ajax
  12. bootstrap select with input field
  13. bootstrap select with custom input
  14. bootstrap select with bootstrap 4
  15. bootstrap select with angular
  16. bootstrap select with thumbnails
  17. bootstrap select with search angular
  18. bootstrap select with filter
  19. bootstrap select with groups
  20. bootstrap select with dropdown

I am having Collapse Panel in Bootstrap which is opening on a click on the title of the tab. I am trying to figure out to open using the hover of the mouse on the total width of the tab but I am not ...

I am having Collapse Panel in Bootstrap which is opening on a click on the title of the tab. I am trying to figure out to open using the hover of the mouse on the total width of the tab but I am not ...

I'm trying to move the dropdown that DataTables uses to determine how many rows to display. One way I thought of was to use jQuery's prependTo()/appendTo() functions, but it feels a bit too hack-y. I ...

I'm trying to move the dropdown that DataTables uses to determine how many rows to display. One way I thought of was to use jQuery's prependTo()/appendTo() functions, but it feels a bit too hack-y. I ...

  1. datatables move pagination to left
  2. datatables move pagination to top
  3. datatables move pagination to center
  4. datatables move pagination
  5. datatables move pagination to bottom
  6. datatables move pagination to right
  7. datatables move pagination outside table
  8. datatables move paging