Forum Moderators: open

Message Too Old, No Replies

php like url include with javascript

no output but no errors though

         

forzatio

5:27 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



Hi there my server doesn't have php/asp.net support, so I have to use another method to get a webpage included on my page.

I tried a SSI-include from which I found out that it's not working for external urls.

Now I have this snippet of javascript:

<script type="text/javascript" src="http://www.example.com/page2.html"> </script>

the code looks fine to me,but I'm not getting any output visible on my page with that code.

Using iframes is not possible because the content wouldn't really be inserted into my page.

I hope someone can help me with this.

joelgreen

7:15 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



page1.html
=================

HTML here
HTML here

<script type="text/javascript" src="http://www.example.com/page2.js"> </script>

HTML here
HTML here

page2.js
=================
document.write("here goes your second page text");

You could also perform document.write for text retrieved by HTTPRequest

xmlhttp=null;

// for Mozilla
if (window.XMLHttpRequest) {
re = new XMLHttpRequest();
}
// for IE
else if (window.ActiveXObject) {
re = new ActiveXObject("Microsoft.XMLHTTP");
}

if (re!= null) {
re.onreadystatechange=stateChange;
re.open("GET","http://www.yourSire.tld/page2.html",true);
re.send(null);
}

function stateChange() {
if (re.readyState==4) {
if (re.status==200) {
document.write(re.responseText);
}
}
}

forzatio

7:50 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



hi, this works for Internet Explorer 6:
You could also perform document.write for text retrieved by HTTPRequest

When I try it with firefox 2 I just get a blank page.

joelgreen

8:21 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



Think the problem is Firefox closes document for writing after it is loaded. So instead you'll have to define some placeholder DIV in the html and replace its contents instead of just document.write. Something like (pseudocode, not tested)

page1.html
=================

HTML here
HTML here

<div id="page2div"></div>

<script type="text/javascript">

re=null;

// for Mozilla
if (window.XMLHttpRequest) {
re = new XMLHttpRequest();
}
// for IE
else if (window.ActiveXObject) {
re = new ActiveXObject("Microsoft.XMLHTTP");
}

if (re!= null) {
re.onreadystatechange=stateChange;
re.open("GET","http://www.yourSire.tld/page2.html",true);
re.send(null);
}

function stateChange() {
if (re.readyState==4) {
if (re.status==200) {
document.getElementById("page2div").innerHTML = re.responseText;
}
}
}
</script>

cmarshall

9:24 pm on Mar 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could also perform document.write for text retrieved by HTTPRequest

As long as the source is from the same server as that serving the page. Otherwise, this won't work as well as the PHP include URI. Same goes for SSI.

I believe that the goal is external URIs. Even ASP ain't so good at resolving external URIs. Only PHP seems to have this ability, and then, only when that functionality [us3.php.net] has been enabled (default).

Now, I have to ask, is this an ISP that isn't providing this support? I think that it is so dirt easy to get an ISP to give this support that you may want to take moving to a more active-server-content-friendly ISPinto consideration.

I use PHP include to serve active content to clients, but you have to carefully craft the page to be included, unless the PHP include is the ONLY text on the page. This is because you can't have a "page within a page."

forzatio

11:00 pm on Mar 5, 2007 (gmt 0)

10+ Year Member



Ok I tried it in a div, still in firefox it doesn't give me a page.
In IE6 I have a security popup which I have to continue first then it works for IE.