1

I made a one-page website which only has text on it and buttons which only purpose is to change the text in the container. And now when I made everything I forgot what if someone wants to link to a specific "page"/text to my site. What would be the best way to do this? So when someone clicks the button, address changes for each paragraph and if someone points to that address specific paragraph would appear/specific button function would do its job.

This is a jquery code for buttons so you can understand better :

$(document).ready(function () { 
    $('[id*=txt]').hide();              
    $('[id*=home]').show();
    $('#btnhome').css({'background-color':'#555', 'opacity':"0.5"});    

    $('.button').click(function (){
        $('[id*=txt]').hide();
        $('.button').css({'background':'transparent', 'opacity':'1'});
        $(this).css({'background-color':'#555', 'opacity':'0.5'});
   });          

    $('#btnhome').click(function () {   
        $('[id*=home]').show();             
    });     

    $('#btnabout').click(function () {              
        $('[id*=about]').show();        
    });    

    $('#btncontact').click(function () {        
        $('[id*=contact]').show();  
    });  
Matt
  • 22,721
  • 17
  • 71
  • 112
user1880779
  • 2,038
  • 8
  • 30
  • 40

1 Answers1

1

You would have to add a parameter to the URL. Like http://mysite.com?page=1

Then you would have to parse out the parameter. Here's a site that will help you with that.

Finally, you would provide for the page parameter in the document.ready function. You could use a switch statement for that.

The Jonas Persson
  • 1,726
  • 1
  • 17
  • 36
  • Hmm sounds a little bit complicating for me, I have just started. Not sure if I would be able to implement everything together without any help. – user1880779 Dec 28 '12 at 02:53
  • How would I change the url with a button click on my site? Just send it normally to that url? and when that url opens parse it and do its thing hmm – user1880779 Dec 28 '12 at 03:03
  • 1
    The solution would look something like this: http://jsfiddle.net/8Lgh2/. This might not be the best solution for linking to specific content, but, unless you want to re-write, it's going to be hard to optimize for search engines while showing/hiding content with jquery. For some browsers you might be able to change the URL without reloading (http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page), but otherwise you are probably better off having the buttons redirect to `http://mysite.com?page=3` etc. – The Jonas Persson Dec 28 '12 at 03:15
  • Thanks a lot, I'll see if I'll be able to do it. But I don't think jquery hiding-showing will affect the optimization for search engines(seo). Even better, search engine spiders should surely crawl through the whole content as I've heard. I like it this way because it somehow feels smooth and fast. What is the other solution to link to other content(best solution)? Just make folders and link to there site.com/about, site.com/contact etc. and just change the content on index.html for each? – user1880779 Dec 28 '12 at 03:50
  • Well, it would be indexed by search engines, but, as your example indicates, it becomes tricky to assign individual URL:s to the "pages". Also, as the site grows, it will be increasingly difficult to manage. There are plenty of other ways to do it, depending on your needs/programming languages you use etc. In general I would recommend separating anything that you want a separate URL for could be a separate page. The exception is when you have something like a blog, where you have one page display generic content. You can still make it smooth using a main template and jquery to load content. – The Jonas Persson Dec 29 '12 at 01:49