By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Event generated when insertAdjacentHTML is executed

P: n/a
hi everyone,
I am writing an extension to a third party application. this
application generates code dynamically using insertAdjacentHTML(). I
want to execute my function whenever the insertAdjacentHTML is called.
Does insertAdjacentHTML() fire any event that i can handle and execute
my function? or is there any other solution?
Thanxs in advance

Dec 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
dexter wrote:
I am writing an extension to a third party application. this
application generates code dynamically using insertAdjacentHTML().
IE only. Look into createElement(), createTextNode() and appendChild()
for a standards compliant approach.
I want to execute my function whenever the insertAdjacentHTML is called.
Does insertAdjacentHTML() fire any event that i can handle
and execute my function?
In IE, maybe you can use the `onload' or `onreadystatechange' event
handlers:
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onload.asp>
<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onreadystatechange.asp>
or is there any other solution?


There is always a solution different from this, usually a better one.
What exactly that would be depends on you: your knowledge, your environment
aso.
PointedEars
Dec 23 '05 #2

P: n/a
On 2005-12-23, dexter <sa***************@gmail.com> wrote:
hi everyone,
I am writing an extension to a third party application. this
application generates code dynamically using insertAdjacentHTML(). I
want to execute my function whenever the insertAdjacentHTML is called.
Does insertAdjacentHTML() fire any event that i can handle and execute
my function? or is there any other solution?
Thanxs in advance


redefine insertAdjacentHTML to run your code also.
new function (){
var iah=insertAdjacentHTML;
insertAdjacentHTML=function( a,r,g,s )
{
your_code_here();
iah( a,r,g,s );
more_your_code_here();
}
}();

the function wrapper hides iah from other javacsript
Bye.
Jasen
Dec 24 '05 #3

P: n/a

hi jasen,

your idea is completely new to me and hence I tried this and it didnt
work. Could you please tell me where did i go wrong
<html>
<body>

<script>
function assign(){
alert('Loaded');
head1.insertAdjacentHTML("BeforeEnd", "<HTML><h2>Inserted
T</h2></HTML>");
}
new function (){
var iah=insertAdjacentHTML;
insertAdjacentHTML=function( a,r)
{
a = "BeforeBegin"
iah( a,r);
alert("bye");
}
}();

</script>


<h3 name = head1 id = head1>
Hello World
</h3>
<input type = text name = text1 value = 0>
<input type = button name= mybutton value = mybutton onclick = assign()>
</body>
</html>
*** Sent via Developersdex http://www.developersdex.com ***
Dec 26 '05 #4

P: n/a
sanjay kaleswaran wrote:
hi jasen,

your idea is completely new to me and hence I tried this and it didnt
work. Could you please tell me where did i go wrong
<html>
<body>

<script>
function assign(){
alert('Loaded');
head1.insertAdjacentHTML("BeforeEnd", "<HTML><h2>Inserted
T</h2></HTML>");
Accessing elements using their name or id as a global variable is not
consistent with W3C standards (though I guess this is only going to
work in IE anyway).

Inserting a second HTML element will cause even IE to barf I'd expect.

}
new function (){
The result of calling the Function object as a constructor should be
assigned to some variable:

var aFn = new Function(){...}
The rest is junk. Even if it did 'work', it would create a function
that has no public methods or attributes and is therefore pretty useless.

insertAdjacentHTML (where implemented) is a method of various host
objects, I don't think you can over-ride them all as simply as that.
There is a discussion on extending host objects here:

<URL:
http://groups.google.com/group/comp....f4761d1572af7e

[...]

<h3 name = head1 id = head1>
It is usual to enclose attribute values in quotes, even though it
isn't always necessary.

<URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2>
In valid HTML, H3 elements do not have a 'name' attribute.
[...]
<input type = button name= mybutton value = mybutton onclick = assign()>


Attribute values that contain brackets '(' or ')' must be quoted.

<input type="button" name="mybutton" value="mybutton"
onclick="assign();">
[...]
--
Rob
Dec 26 '05 #5

P: n/a
Thanx for tip

Dec 29 '05 #6

P: n/a
VK

dexter wrote:
hi everyone,
I am writing an extension to a third party application. this
application generates code dynamically using insertAdjacentHTML(). I
want to execute my function whenever the insertAdjacentHTML is called.
Does insertAdjacentHTML() fire any event that i can handle and execute
my function? or is there any other solution?
Thanxs in advance


Everything below is naturally IE only and exclusively:

insertAdjacentHTML seems to fire an "abstrasted" propertychange event:-
instead of a real property name event.propertyName returns event
handler name "onpropertychange". It seems like the system feels that
something is changed but not sure yet what exactly. One can use it on
its own risk like:
....
document.body.onpropertychange = f1;
....
function f1() {
if ((event.propertyName == 'onpropertychange') &&
(event.srcElement.tagName == 'BODY')) {
// someone is playing with insertAdjacentHTML
}
}

Again: it seems like a undocumented feature rather than something you
can completely trust.

Dec 29 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.