rlemon
05-25-2005, 08:11 PM
ok,
I have a page with a div on it (titled 'mainDoc') and a serise of links,
When the user clicks on a link the following code returns the HTML source of another webpage to a string.
I then dump the string into the div using innerHTML
function getHeader(tab){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new
ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
var doc = "tab_content/"+tab+".php";
xmlhttp.open("GET", doc, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var main = document.getElementById('mainDoc');
var html = xmlhttp.responseText;
main.innerHTML = html;
}
}
xmlhttp.send(null)
return;
}
The problem is this:
In the 'return string' (i.e var html ) there is some JS code.
This code does not get executed, ever...
so for example:
if var html contained
<script>alert('here');</script>
No alert would happen.
any ideas or help would be great!
I have a page with a div on it (titled 'mainDoc') and a serise of links,
When the user clicks on a link the following code returns the HTML source of another webpage to a string.
I then dump the string into the div using innerHTML
function getHeader(tab){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new
ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
var doc = "tab_content/"+tab+".php";
xmlhttp.open("GET", doc, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
var main = document.getElementById('mainDoc');
var html = xmlhttp.responseText;
main.innerHTML = html;
}
}
xmlhttp.send(null)
return;
}
The problem is this:
In the 'return string' (i.e var html ) there is some JS code.
This code does not get executed, ever...
so for example:
if var html contained
<script>alert('here');</script>
No alert would happen.
any ideas or help would be great!