Hi,
I'm new to jQuery and web developing, so when I finally got some difficult code working (that is, difficult to me), I was pretty proud ;-)
Just to check if it REALLY worked, I opened my page in multiple browsers. Though I coded everything using Firefox (the browser which actually showed what it should show), the other browsers (Safari, Chrome and Opera) just crashed on this script or showed none of it.
This was the general idea:
I am developing a hard coded website where I want to create a general news page filled with news items, and multiple news item ('ni_*') pages. The ni_1.html, ni_2.html etc. each contain some news of which a teaser (short version with a 'read more' button) should be showed on the general news page. I also wanted to check how many ni_*.html pages exist, so the script wouldn't have to render too many <span>s.
As you can see, I am loading the necessary data from the external files using the .load command, and put it also in a while loop to keep creating news items on the general news page for as long as the script can find external files.
I have put some other scripts before this last one, but these alway did work. So I'll just past the new script here:
var i = 1;
while(i > 0) {
var stoppen = 0;
var e = 0;
var charCount = 300;
$('.span8border').append($('<span></span>').addClass('NI'+ i));
$('.span8border > .NI'+ i).load('ni_'+ i +'.html .span8border > h1, .span8border > span > p', function (){
var niHeader = $(this).find('h1');
var niParagraph = $(this).find('p');
niHeader.replaceWith(function() {
return '<h4>'+ $(this).html() +'</h4>';
});
niParagraph.replaceWith(function() {
var niSliced = $(this).text().slice(0, charCount);
return '<p>'+ niSliced +'... <a href="ni_'+ e +'.html">Lees meer</a></p>';
});
if($(this).text() == "") {
stoppen = 1;
};
e++;
});
if (stoppen == 0) {
i++;
}
else {
i = 0;
$('.span8border > span').last().remove();
};
};
To me it seems it has got something to do with the while loop, since Safari and Chrome kept trying to render this page for a long time. But then again, Opera opened the page without a sweat and just showed an empty (no scripts) page.