Register and join over 40,000 other developers!
Recent Topics
-
Tekken 7
IsrealJones - Mar 22 2021 07:21 AM
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
New to the community
iwinx - Jul 17 2020 12:02 PM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

undefined TypeError only on iPhone — JavaScript, HTML5 canvas_context.measureText
Started by SexyBachelor, Nov 10 2012 11:30 AM
typeerror iphone javascript measuretext canvas undefined html5
1 reply to this topic
#1
Posted 10 November 2012 - 11:30 AM
Hi there. I'm working on a website that uses HTML's canvas to draw text onto the screen.
There is an error on iPhone reading
"TypeError: 'undefined' is not an object"
This error propagates from the call:
(canvas 2d context).measureText("text");
The website works perfectly well on many operating systems and browsers that I have tested. The problem only persists on iPhone.
Here is a link to full details: http://stackoverflow...3301056/1433127
Has anyone else run into this problem? measureText is such an essential function to be glitched up like that.. I'm looking for a workaround if anyone has one.
There is an error on iPhone reading
"TypeError: 'undefined' is not an object"
This error propagates from the call:
(canvas 2d context).measureText("text");
The website works perfectly well on many operating systems and browsers that I have tested. The problem only persists on iPhone.
Here is a link to full details: http://stackoverflow...3301056/1433127
Has anyone else run into this problem? measureText is such an essential function to be glitched up like that.. I'm looking for a workaround if anyone has one.
#2
Posted 10 November 2012 - 11:50 AM
I have confirmed that this short code produces the error:
This code works well on mac safari, but not my friend's iPhone safari (unhacked etc...) I'm working on testing it on more iPhones at the moment
Edit: tested on two iPhones now. The newer iPhone (5) draws the red box over the entire canvas but does not draw the text. The older iPhone (4s) draws neither. I have also modified the font to use the standard font "Arial" as seen in the above code.
<html> <head> <title>iPhone test page --- is measureText the issue?</title> <script type="text/javascript" src="font/canvas.text.js"></script> </head> <body height="400px"> <canvas id = "drawArea"></canvas> <script type="text/javascript"> var can = document.getElementById("drawArea"); var c2d = can.getContext("2d"); c2d.fillStyle = "red"; c2d.globalAlpha = 1; c2d.fillRect(0,0, can.width, can.height); c2d.fillStyle = "black"; c2d.font = "12px Arial"; var text = "Hello, world!"; var width = c2d.measureText(text).width; c2d.fillText(text, can.width/2 - width/2, can.height/2- 6); </script> </body> </html>
This code works well on mac safari, but not my friend's iPhone safari (unhacked etc...) I'm working on testing it on more iPhones at the moment
Edit: tested on two iPhones now. The newer iPhone (5) draws the red box over the entire canvas but does not draw the text. The older iPhone (4s) draws neither. I have also modified the font to use the standard font "Arial" as seen in the above code.
Also tagged with one or more of these keywords: typeerror, iphone, javascript, measuretext, canvas, undefined, html5
Tutorial Forums →
HTML, CSS and Javascript Tutorials →
A silly contraption using a physics engineStarted by tutor, 17 Dec 2019 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Userscript is missing something, which I can't find. Someone please fill ItStarted by Sudhareddy, 31 Jan 2019 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Javascript Closures Help. Unable to save copy of "count' within an IIFE functionStarted by An Alien, 11 Sep 2017 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
What is JavaScript used for?Started by dasswadesh, 25 Feb 2017 ![]() |
|
![]() |
||
Tutorial Forums →
HTML, CSS and Javascript Tutorials →
Google Map cannot be displayed Inside Bootstrap Modal ViewStarted by mutago, 31 Jan 2017 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download