Easy way to load content without page refresh

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
fredd
New Member
New Member
Posts: 6
Joined: Tue Sep 16, 2008 7:39 am

Easy way to load content without page refresh

Post by fredd »

First make sure you have jQuery in the head section.
For example like this:

Code: Select all

<__script__ type="text/javascript" src="uploads/jquery.js"></__script>
Then add this to the head section:

Code: Select all

<__script__ type='text/javascript'>
$(document).ready(function(){
	$("a").click(function() {
		var contentDivId = 'content';
		var loadImgAlt = 'Loading content, please wait..';
		var loadImgUrl = 'uploads/images/loading.gif';
		var temp = $(this).attr("href")+"&showtemplate=false";
		var temp2 = temp.replace(/amp;/g,'');
		$("#"+contentDivId).html("<img src='"+loadImgUrl+"' alt='"+loadImgAlt+"' />");
		$("#"+contentDivId).load(temp2);
	});
});
</__script>
SimonSchaufi

Re: Easy way to load content without page refresh

Post by SimonSchaufi »

well done!
is there an easy way to work with anchors in the url? i see that in facebook for example or here:

http://www.be-lufthansa.com/

the cool thing is that if the url with an anchor is not possible to load in the div, it refreshes the whole page with the correct url.

To see what i mean, do the following:

- click on a link: result: # in the url with the new target
- click refresh button in the browser: part after # will be used to redirect to the correct url
JeremyBASS

Re: Easy way to load content without page refresh

Post by JeremyBASS »

This is not a CMSMS trick here... sorry... thought it's handy for any site... I did something little more elaborate a ways back...

http://www.hellscanyonsportfishing.com/ ... d-cam.html

just does that every 30 sec... but I didn't post it here though that whole site is CMSMS driven, as it's a jQuery topic... and there are much shorter ways to do this...

This is just My2Cents ... and by now means I'm trying to knock you from sharing... Have a great weekend...

Cheers
Jeremy
JeremyBASS

Re: Easy way to load content without page refresh

Post by JeremyBASS »

here was an old post in the gen area... it has some good stuff there too

http://forum.cmsmadesimple.org/index.ph ... 003.0.html

Cheers
jeremyBass
viebig

Re: Easy way to load content without page refresh

Post by viebig »

SimonSchaufi wrote: well done!
is there an easy way to work with anchors in the url? i see that in facebook for example or here:

http://www.be-lufthansa.com/

the cool thing is that if the url with an anchor is not possible to load in the div, it refreshes the whole page with the correct url.

To see what i mean, do the following:

- click on a link: result: # in the url with the new target
- click refresh button in the browser: part after # will be used to redirect to the correct url
Actually there is, not rally simple, but having archors pointing to pages is a really bad to search engines  and social bookmarks.

Regards
SimonSchaufi

Re: Easy way to load content without page refresh

Post by SimonSchaufi »

viebig wrote:
SimonSchaufi wrote: well done!
is there an easy way to work with anchors in the url? i see that in facebook for example or here:

http://www.be-lufthansa.com/

the cool thing is that if the url with an anchor is not possible to load in the div, it refreshes the whole page with the correct url.

To see what i mean, do the following:

- click on a link: result: # in the url with the new target
- click refresh button in the browser: part after # will be used to redirect to the correct url
Actually there is, not rally simple, but having archors pointing to pages is a really bad to search engines  and social bookmarks.

Regards
well, better then not showing any difference like the code from fredd. if you load another content in the content area there is no way to find out WHAT content. with the anchors you know it exactly.
spiriralph
Forum Members
Forum Members
Posts: 36
Joined: Sat Jun 27, 2009 10:52 am

Re: Easy way to load content without page refresh

Post by spiriralph »

User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

Re: Easy way to load content without page refresh

Post by opawaldburger »

hey!

I would love to load page content without refreshing the site! So I tried this method and it simply doesn't work. Is the script out of date and not compatible any more or have I done anything wrong?

I created a special site for testing, which can be reached here. Site "Test1" is linked to "Test2" and back - so the content should be loaded.

I inserted both scripts, though nothing happens!

Best wishes,
Opa
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
Locked

Return to “Tips and Tricks”