PDA

View Full Version : Resolved Ajax includes script - css help



BlackburnRavers
11-12-2010, 12:58 PM
1) Script Title: Ajax includes script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxincludes.htm

3) Describe problem: Dark backgrounds showing up white.


How do guys, i've been looking for an alternative to iframes and i came across this script because it uses the same css as the internal page its on.

The problems im having is that when i use a dark background it seems to overwrite it and uses a white background instead. Is there anyway i can prevent this from happening and make it use the correct body background set in the css file?

Heres some screenshots of what i mean.
White background (This is correct)
IMAGE HERE (http://www.blackburnravers.com/public/site_images/public-img/default1.png)

What dark 1 should be like:
IMAGE HERE (http://www.blackburnravers.com/public/site_images/public-img/dark2.png)

How dark 1 is displaying (This is incorrect)
IMAGE HERE (http://www.blackburnravers.com/public/site_images/public-img/dark1.png)

the problems seem to occur with this code:

<script type="text/javascript">

/***********************************************
* Ajax Includes script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//To include a page, invoke ajaxinclude("afile.htm") in the BODY of page
//Included file MUST be from the same domain as the page displaying it.

var rootdomain="http://"+window.location.hostname

function ajaxinclude(url) {
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.open('GET', url, false) //get page synchronously
page_request.send(null)
writecontent(page_request)
}

function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
document.write(page_request.responseText)
}

</script>

Hope somebody can help me and point me in correct direction.

jscheuer1
11-12-2010, 02:00 PM
Since you are obviously dealing with a forum package of some kind which uses server side code - PHP probably. It would be better to use a server side include.

What happens when you use this script is that what once were two pages now become one. So there must be something on the imported page or on the top page that's causing that white. This can often be determined by viewing the generated source code of the page in Firefox's developer tools extension. Unfortunately (as far as I know) there aren't other reliable tools for this in other browsers, and if Firefox 'gets it right' (displays the page as intended), there may be little to be learned from this view.

Is this browser specific?

Have you tested in only one browser? If so, which?

In any case, the effect of importing content via javascript is slightly different than using a server side include. Either can give rise to unexpected results, but the mechanisms whereby these arise differ somewhat.

Unlike with iframe, any include must not have any code on it other than that required for insertion. That means no DOCTYPE, no opening or closing html, head, title or body tags, and no meta tags. All these tags belong on the top page only. Other tags to avoid (though these sometimes can work out, more likely with a server side include than with a javascript include) are script and style (both on page stylesheets and link rel="stylesheet" external stylesheets).

A server side include is almost always to be preferred though because it allows you to use any browser's 'view source' to see the code being served. Often this is the only method one can use to diagnose problems.

BlackburnRavers
11-12-2010, 03:00 PM
Thanks for your response john, much appreciated, i did try it on firefox, chrome & IE and it resulted in the same outcome.

But i didn't know i couldn't use any DOCTYPE, no opening or closing html, head, title or body tags. I have just removed all these settings from the file and everything is now working how it should be.

Thank you for your advice and help. Respect mate :):):)

Cheers, Blackburn Ravers