Results 1 to 3 of 3

Thread: Ajax includes script - css help

  1. #1
    Join Date
    May 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Ajax includes script - css help

    1) Script Title: Ajax includes script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...axincludes.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

    What dark 1 should be like:
    IMAGE HERE

    How dark 1 is displaying (This is incorrect)
    IMAGE HERE

    the problems seem to occur with this code:
    HTML 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.
    Last edited by BlackburnRavers; 11-12-2010 at 03:27 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    BlackburnRavers (11-12-2010)

  4. #3
    Join Date
    May 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •