Results 1 to 4 of 4

Thread: Ajax Content External CSS Conflict/Issue

  1. #1
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Ajax Content External CSS Conflict/Issue

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    3) Describe problem:

    This script works fantastically except for one issue for me - loading styles.

    The basic gist of my issue is this: My Ajax content script loads in a page that is auto-generated by some race-timing software called "Orbits". Because of this, I have no control over the page's code, and it gets updated on race nights when I am not available/present, so altering their HTML is not an option.

    The auto-generated page has styling in the head tags between <style></style> tags, and does not use selectors to restrict where they go. This means when I load in the html document, the styles in that page are applied to the whole site.

    Is there a way I can strip the <head> or <style> tags when loading an external page in using the script, or a way to override that <style> stuff during the function?

    To see the page in action (designed as an iPhone web app so best viewed on one if possible), you can go to:

    http://www.wss-live.com/iui/web-app/#_home

    Click "Live Results"
    Select "A Main" from the drop down menu - that should load in the external file.

    The external file:
    http://www.wss-live.com/grids/WSS%20...0A%20Main.html

    Really hoping someone can help me! Thanks in advance!

  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

    I don't have an iPhone to test on. However, I can tell you that what you want can be done. But it's pretty complicated to modify this script to do it. On the other hand, you're already using jQuery. With jQuery it's relatively easy to do.

    What I would suggest is to scrap the Ajax Content script and update to jQuery version 1.6.4. Then where you have:

    Code:
    ajaxpage(gridID, 'contentarea');
    replace that with:

    Code:
    $.ajaxSetup({cache: false});
    $('#contentarea').load(gridID + ' div:not("div:first"),table');
    You only need to declare:

    Code:
    $.ajaxSetup({cache: false});
    once for the page, so that could go before the function and then you could chain off of the .empty() for the #contentarea selector:

    Code:
        <script>
    		$.ajaxSetup({cache: false});
    		function grids()
    		   {
    		   var g = document.gridform.gridlist.selectedIndex;
    		   var gridID = document.gridform.gridlist.options[g].value;
    		   var gridID = "http://wss-live.com/grids/" + gridID + ".htm";
    		
    						   $("#loading").fadeIn(200);
    						   $("#loading").css("visibility", "visible");
    						   
    		   $('#contentarea').empty().load(gridID + ' div:not("div:first"),table');
    		   
    						  $("#loading").fadeOut(3000);
    		   }
    	</script>
    The browser cache may need to be cleared and/or the page refreshed to see changes.
    Last edited by jscheuer1; 10-17-2011 at 04:08 AM. Reason: add - The browser cache . . .
    - 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:

    wazman21 (10-17-2011)

  4. #3
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you for the detailed reply John, very much appreciated!

    I was still having trouble with the JQuery load function not working, so here is the solution I ended up using (which seems to be working very well and quickly):

    Using JQuery, instead of the load function, I used the .ajax() function, and appended the HTML to the div area. Instead of racking my brain trying to omit the stylesheets/head tags, I finally clicked it would be better to simply append a stylesheet after calling the .ajax() function that overrides the problematic tags. Here is the result:

    <script type="text/javascript">
    $.ajaxSetup({cache: false});
    function liveresults()
    {
    var live = document.liveform.livelist.selectedIndex;
    var liveID = document.liveform.livelist.options[live].value;
    var liveID = "http://wss-live.com/grids/" + liveID + ".html";

    // STILL HAD PROBLEMS WITH THE FOLLOWING LINE:
    // $('#liveresultsarea').empty().load(liveID + ' div:not("div:first"),table');

    // THIS SOLUTION IS WORKING:

    $("#liveresultsarea").empty();

    $.ajax({
    url: liveID,
    context: document.body,
    cache: false,
    success: function(html){
    $("#liveresultsarea").append(html);
    }
    });

    var link = $("<link>");
    link.attr({
    type: 'text/css',
    rel: 'stylesheet',
    href: 'cssfixer.css' /* custom stylesheet to fix problem css, using "!important" tags */
    });
    $("head").append( link );

    }
    </script>

  5. #4
    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

    Great! If that fixes it though, and if you're doing that more than once on a page, it would be simpler just to have this in the head of the page:

    HTML Code:
    <link rel="stylesheet" href="cssfixer.css" type="text/css">
    Last edited by jscheuer1; 10-17-2011 at 07:20 AM.
    - John
    ________________________

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

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
  •