PDA

View Full Version : New setup, getting "object doesnít support this property or method"



jjmiller1980
28 Jun 2011, 8:09 AM
I just set up Ext JS in my project, and am coming across a problem. Iíve copied the ext-all.js and the ext-base.js into my project, along with all the images and CSS. Iíve set up my first web page that uses Ext JS just to test and make sure itís working correctly.

When I load the page, this code DOES work, it gives me my alert as expected, but I also get a JavaScript error saying ďobject doesnít support this property or method". If I point the file to ext-all-debug.js, it points to line 520, which is the line after the else clause of the insertHtml function. The exact line is the one in red below:



insertHtml : function(where, el, html){
....
if (el.insertAdjacentHTML) {
....
} else {
range = el.ownerDocument.createRange();
setStart = 'setStart' + (endRe.test(where) ? 'After' : 'Before');
....
}

Here is my source code:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<title> extTest </title>

<link rel="stylesheet" type="text/css" href="../extjs/css/ext-all.css" />

<script type="text/javascript" src="../extjs/js/ext-base.js"></script>
<script type="text/javascript" src="../extjs/js/ext-all-debug.js"></script>

<script type="text/javascript">
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = '../extjs/images/s.gif';

Ext.Msg.alert('This is a test');
});
</script>

</head>
<body>
This is a test.
</body>
</html>

Anybody have any idea what might be causing this?

Uberdude
28 Jun 2011, 8:17 AM
Are you using IE? This rings a faint bell about some IE bug in which createRange() gets broken if there is a text node at the beginning of the DOM, so try removing the whitespace in your html file before the doctype.

jjmiller1980
28 Jun 2011, 8:27 AM
I gave this a try, still giving the error. I'm using IE 8. I took out that space and it didn't seem to make a difference. Just for grins I took out every blank line in the page and it didn't make a difference. Also, in case it makes a difference, I'm using Ext 3.4.0.

skirtle
30 Jun 2011, 7:21 AM
It's because the first node in your body is a text node rather than a proper element. When it goes to create the shadow for the messagebox it tries to insert it into the DOM before the first element in the page. For a proper element in IE it will have the method insertAdjacentHTML() and go into the if clause but for a text node that method doesn't exist so it's incorrectly falling into the else statement.

I think it counts as a bug but it's a bit of an edge case... real apps don't have text as the start of their body.

Uberdude
1 Jul 2011, 1:47 AM
Ah right, a text node at the start of the body, as well as before the <html>, causes this issue too. Here's a four-year-old thread (answered by Jack Slocum himself!) about the same issue, closed with the workaround of sticking some other tag like a comment in before the text: http://www.sencha.com/forum/showthread.php?7912-CLOSED-owner.createDocument.createRange-JS-error .