Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript from Ajax 1

Status
Not open for further replies.

WebRic

Technical User
Sep 21, 2004
95
0
0
GB
Hi,

Is this possible?

I use Ajax call to a page.

Within the called page I create some html which also contains a javascript element with a standard function in. I write this all into a variable escaping quotes and loop over it so there is about 50 characters per line.

var myNewContent = " "
myNewContent += "blah"

I then write this to the request page using .innerHTML.

Everything works fine, apart from the javascript written to the innerHTML doesn't seem to work...

Any ideas why?

R
 
Use instead the .insertAdjacentHTML method. It is ie-proprietary. To make it cross-browser (ie/moz/ff), add a header script section defining the prototype.
[tt]
<script language="javascript">
//ref //accredited Thor Larholm
HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML);
}
</script>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top