Object doesn't support property or method remove - javascript

I am using extjs and trying to remove a dom element dynamically like this-
if (Ext.getElementById('a'))
Ext.getElementById('a').remove();
This works fine in Chrome. I am running application on IE9 as well but it throws the error- Object doesn't support property or method remove
Please let me know if there is a workaround.

Ext.getElementById() is a private method - you may want to consider using Ext.get() instead.
Anyhow, if it works in Chrome and not in IE, most likely your dom is invalid - search for missing closing tags, or alternatively validate your dom using an online validator. Also see this.

Related

QlikView with D3

I am trying to develop a custom object extension in QlikView using d3.js
First I tried to manually code everything, but I encountered a error like the figure below. It looks like QlikView does not support some d3_v2.js methods.
I also tried using a newer version of d3 (d3.min.js)...
Ultimately, I tried using a tested custom component (https://qvextanimatedscatter.codeplex.com/) , but it also ran on the same error...
Any clues?
Does QlikView has a bug?
Did you google the error message? See here;
SCRIPT438: Object doesn't support property or method IE
After some days searching the Internet I found that this error usually
occurs when an html element id has the same id as some variable in
the javascript function. After changing the name of one of them my
code was working fine.
It might solve the problem.

Javascript broken after moving from IE8 to IE11: "Object doesn't support property or method 'all' "

I was just forced into a browser upgrade (IE8 to IE11) while in the middle of testing. I've lost some essential functionality with some javascript that suddenly doesn't work in my .NET site.
This section of the code was written when I was in grade school, so I'm not extremely familiar with it, but what seems to be the problem is a call to form.all. I have to assume that call was built into javascript at some point - there's no definition for it in the code.
There are 7 "if statements" that use form.all and they are all written the same way:
if(form.all(cTag + "PersonNum") != null)
form.all(cTag + "PersonNum").value = personNumber;
The error:
JavaScript runtime error: Object doesn't support property or method 'all'
In newer versions of JavaScript, is there a version of form.all that performs the same action? All I really need is for someone to point me in the right direction.
A weird note: the same JavaScript code IS working in production on IE11
EDIT Ok, I found a line that was minimized. It looks like form is a created variable.
var form = document.forms(0);
EDIT2 Compatibility view/mode was the solution after all. I had added our production site's domain to the compatibility list and didn't think about it; adding 'localhost' fixed the issue. You just have to set it to the right domain first for it to work :)
Check the browser compatability mode when your running in production it's probally on IE8.
You can use obj.getElementsByTagName("*")
You could also add an All method to the prototype if it's not there.
IE introduced an all property for certain DOM objects (e.g. document) but it was never part of any W3C standard. It allowed access to DOM objects by name or ID using:
var element = document(elementNameOrID);
or
var element = document[elementNameOrID];
that is, it is a property that could use the same syntax as a method. Neat. Some other browsers supported it for compatibility, but it pretty much went out of use with IE 6 (not sure when IE started supporting getElementById, I think it was IE 5). But IE continued to think name and ID attributes were the same thing until IE 8 in standards mode.
Support for all has been dropped from IE 11 in standards mode.
If form is a reference to a form element, and cTag + "PersonNum" is the name of a form control, then the simplest fix is to change:
form.all(cTag + "PersonNum").value
to
form[cTag + "PersonNum"].value
which takes advantage of named form controls being made properties of the form that contains them. This behaviour is standardised and supported by browsers from the very beginning (i.e. every where) and is future proof (it's not going to change).

How to prevent empty namespace generation in Firefox?

What I want to do is to serialize a DOM to XML. So I create a new document
var doc = document.implementation.createDocument ('http://AOR-AppML.org', 'Application', null);
and I add nodes, attributes etc. This is working fine.
The problem is that I have different behaviours with XMLSerializer in Google Chrome and Mozilla Firefox.
Chrome console output:
<Application xmlns="http://AOR-AppML.org" name="SoRiN"><ObjectType name="ObjectTypeName"/><Enumeration name="EnumerationName"/></Application>
Firefox console output (notice the xmlns=""):
<Application xmlns="http://AOR-AppML.org" name="SoRiN"><ObjectType xmlns="" name="ObjectTypeName"/><Enumeration xmlns="" name="EnumerationName"/></Application>
I don't want to generate that empty namespace. I've read this namespaces indicates that the corresponding elements have no default namespace (http://www.w3.org/TR/xml-names/#defaulting), but actually I want them to be in the same namespace as Application.
Is there any way to prevent the namespace generation in Firefox?
P.S. - yes, I've followed the advice from this post -> How to prevent the namespace generation?
UPDATE
Here is a fiddle to play with.
You have to use the method createElementNS, instead of createElement, since the latter creates an element with empty namespace URI.
Chrome serializes incorrectly the document (if you parse the string you would get a different document, with namespace URIs wrong), Firefox does the job right. Actually a bug was filed and marked as solved, but the problem seems to be still there.
So, simply replace doc.createElement(yourElementName) with doc.createElementNS('http://AOR-AppML.org', yourElementName).

In what situation would document.open() return null?

I'm trying to understand an intermittent script error that I am seeing in a JavaScript intensive thin-client application running under Internet Explorer 6 and Windows XP. The root cause of the problem is that the following function call returns a null value (however it does succeed without an error):
var doc = targetWindow.document.open("text/html","_replace");
Where targetWindow is a window object.
Neither targetWindow nor targetWindow.document is null and so I'm struggling to understand why this call would return null. My interpretation of the documentation is that this method shouldn't ever return null.
This code has been unchanged and working perfectly for many years - until I understand why this is happening I'm not sure either how I might handle this, or what might have changed to cause this to start happening.
What might cause this function call to return null?
According to the documentation you should be passing "replace", not "_replace". Try this instead:
var doc = targetWindow.document.open("text/html", "replace");
Since you say your code has worked for years, then it is likely that something has changed and the above suggestion may not be the issue. However, it is still worth a try.
Have you changed any js files / libraries you are using in your application lately? Also, are you using any browser plugins within the page? It is possible that a newer version of either of these could be somehow affecting your call to "document.open".
document.open() does not have any parameters by W3C standard. Check out this link: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-72161170
I recommend you to use W3C documentation instead of Microsoft's one because with W3C you are sure it works on all modern browsers, while Microsoft is well known for adding extensions that, of course, works only in their own products. It's called EEE (Embrace, extend and extinguish).
Simply use document.open() without arguments. There are ways to manipulate user history, but that's called bad programming practice. History is user's private data and web application should not try to manipulate it.

JavaScript not working in IE but works in FireFox?

post_form_id = escape(findelementbyname("post_form_id"));
fb_dtsg = escape(document.getElementsByName("fb_dtsg")[0].value);
cookie_user_uid = document.cookie.match(/c_user=(\d+)/)[1];
xhpc_composerid = escape(findelementbyname("xhpc_composerid"));
It seems as if post_form_id and fb_dtsg cannot execute properly in Internet explorer, but work in Firefox?
What would I have to change to have it working in both?
One Question : Are you able to search by Id instead? If so, getElementById(...) will be a better choice.
To get elements by name, you will use getElementsByName("...") - but that will return an array of elements, from which you will need to take the first item.
Typically what you describe regarding inconsistency across browsers is caused by syntax problems...
I believe that this:
findelementbyname(...)
should be this:
FindElementByName(...)
Also run your code through an online syntax checker like JSLint
Although you can make javascript cross browser compatible without extra libraries (such as JQuery), it can often become unneccesarily painful to do so.
I would recommend the use of JQuery.

Categories

Resources