Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

PDF to HTML5 conversion – innerText in Firefox

39 sec read

One of the ‘issues’ with writing HTML5 is using commands which work across all browsers. I came across a good example of this while debugging an issue this morning…

In a previous release I added this code snippet

if(actualWidth>20 && actualWidth>rawWidth && rawWidth!=actualWidth & el.innerText.search(' ') > -1){

It actually turns out that this causes issues in Firefox because Firefox does not support innerText and fails – anything in the Javascript after it meets this (which in this case was all the canvas drawing code) fails. The solution is to use textContent instead.

if(actualWidth>20 && actualWidth>rawWidth && rawWidth!=actualWidth & el.textContent.search(' ') > -1){

and happily textContent also works on other browsers. But it does highlight that you need to be careful when writing HTML5 for cross-platform support.

Luckily there is a really good site which lists browser compatibility on all HTML5/canvas/Javascript features at http://caniuse.com/ which is now on my bookmarks. Do you have any recommendations for cross-browser support?



Converting PDF/ Office Documents to HTML?

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2021. All rights reserved.