/    Sign up×
Community /Pin to ProfileBookmark

calling external html page without SSI

Can anybody help me out!? i’ve tried JS and Ajax but im a huge newbie in both areas.

im trying to call content from an external page into a specified div on my index page. im not having any luck trying to figure this out on my own!

I do not want to use SSI!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayMay 09.2008 — Here's one I wrote a while back that works in IE and FF:

[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>JS Include</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getFile(fileName){
oxmlhttp = null;
try{
oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e){
try{
oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
return null;
}
}
if(!oxmlhttp) return null;
try{
oxmlhttp.open("GET",fileName,false);
oxmlhttp.send(null);
}
catch(e){
return null;
}
return oxmlhttp.responseText;
}

var incArr;
window.onload = processInclude;

function processInclude() {
incArr = document.getElementsByTagName("inc");
dNode=document.createElement("div");
dNode.innerHTML=getFile(incArr[0].attributes.file.nodeValue);
tNode=incArr[0];
tNode.parentNode.replaceChild(dNode, tNode);
//Array is now invalid so a regular loop won't work
if(document.getElementsByTagName("inc").length > 0) processInclude();
}
</script>
</head>

<body>

<inc file="header.inc" />
<div><br />Some random text<br /></div>
<inc file="footer.inc" />
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@Sirin86May 09.2008 — So you're trying to drop HTML from another page into a div without using JS? With AJAX you'd probably have to use something server-side, unless you request the object directly.

You could use an iframe, but the best way to do it I think is through AJAX. And the best way to do AJAX is with a library, a good one is [url=http://www.prototypejs.org/]Prototype[/url]. Then, you can go:
<i>
</i>&lt;div id = "myDiv"&gt;&lt;/div&gt;
&lt;input type = "button" onclick = "fillDiv()" value = "Fill Div" /&gt;
&lt;script&gt;
function fillDiv(){
new Ajax.Updater("myDiv", "path/to/file.html");
}
&lt;/script&gt;

This requests the file at the URL you specify and dumps the content into the element you specify (in the example, myDiv).
×

Success!

Help @absolutmgd13 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...