tags:

views:

347

answers:

3

I was wondering why Chrome doesnt parse a page correctly when I add a page loaded by the .Load() method

I integrate a page with full html, head and body tags and it just ignores everything there except my content. Making it impossible to integrate a jquery script...

Am i overlooking something? Does chrome filter out the html, head and body tags when load()ing?

2nd question... Is it needed to use full html, head an body tagging on the integrated page, or can i just pass everything between the body tag and but the script in there?

EDIT:

The element that triggers the colorbox:

<a class="teaminfo cboxElement" href="news/teaminfo.htm">Lees verder</a>

the Page thats loaded. ( in short)

<head>
<title></title>
<link type="text/css" href="/style/style.css" rel="stylesheet"  />
<link type="text/css" media="screen" rel="stylesheet" href="/style/style.css" />

<meta name="keywords" content="" />
<script src="/js/jquery-1.4.1.min.js" type="text/javascript"></script>
<script  src="/js/jquery.colorbox-min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function()
    {
        $(".teaminfo").colorbox();
    });
</script>

3rd and 4th question: If i put a script in the body element of the page, will this use the calling page head scripts, and will it validate at w3c?

A: 

On which object do you use the .load function?

Saebekassebil
im calling a colorbox on a link element. IN FF and IE it works, on Chrome it filters out the thing.... Is there by any chance a .live() method for the document ready function?
Rickjaah
+1  A: 

The load method has an implicit (and unavoidable, I believe) filter on the body of the document. This used to be documented on the jQuery site, but seems to be missing in the current documentation. Consider that load places the returned data inside a container in the body and it becomes obvious why it filters out everything outside the body -- it's illegal to have multiple html and/or head elements in the document and they are most certainly illegal inside any element that would be contained in the body of a document.

Note: I'm easily able to load script elements that appear in the body of the document. Perhaps all you need to do is move them from the head to the body of the fragment. One caveat is that the script may need to be local to your site. Browsers may refuse to load remote scripts loaded via ajax due to security concerns.

tvanfosson
+1  A: 

You can do this as a work-around for the script stripping (updated to match your posted code):

If your call is this:

$("#myElem").load("myPage.htm");

You can try with a callback added (if you pass params, callback is the third param):

$("#myElem").load("myPage.htm", function(resp) {
  $('.teaminfo', resp).colorbox();
});

Just place the <script src="/js/jquery.colorbox-min.js" type="text/javascript"></script> in your main page instead now. This will call .colorbox(); on the .teaminfo elements only within the response when it comes in.

For the other question, yes, you can pass what's in the body only and see the same result.

Nick Craver