/    Sign up×
Community /Pin to ProfileBookmark

<div> dynamic content from file

I am attempting to change the content of a <div> layer by accessing a external html file. Is this possible? I am able to change the content using innerHTML but only from a string or string varible. Please help….

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@methodpgDec 30.2005 — HTML:

[CODE]<DIV id='myDiv'></DIV>[/CODE]

Javascript:
[CODE]<script>
function getHTTPObject(){
var xmlobj;
if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){xmlobj.abort();}
try{xmlobj=new XMLHttpRequest();}
catch(e){try{xmlobj=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){xmlobj=null;
return false;}}
return xmlobj;
}

var http = getHTTPObject(); // We create the HTTP Object

function handleHttpResponse() {
if (http.readyState == 4) {
document.getElementById('myDiv').innerHTML = http.responseText;
}
}

function loadPage(sourceURL)
{
http.open("GET", sourceURL, true);
http.onreadystatechange = handleHttpResponse();
http.send(null);
}
}

loadPage('index2.html');
</script>[/CODE]
Copy linkTweet thisAlerts:
@iceman0authorDec 30.2005 — Thanks, I'll try it...
×

Success!

Help @iceman0 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...