Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Javascript and non javascript link

  • 21-02-2008 4:37pm
    #1
    Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭


    Hi Lads,

    I'm trying to sort out my "next" links and alphabetical on this page:

    www.ratemypub.ie/cork/

    I want to
    • keep the javascript version
    • add a javascript command or link to go to the top of the page when it has been clicked
    • add a regular link
    • add code to recognise when JS is off

    Can I just have

    <a href="link" onclick="do some java">blah blah</a>

    What's the java to go to the top of the page, I could do anchoring and so on but then I could do regular links

    Thanks
    Gary


Comments

  • Closed Accounts Posts: 1,200 ✭✭✭louie


    add #top to the link
    <a href="link#top" onclick="jsfunction();return false;">blah blah</a>

    and set the anchor name inside the div that will refresh the content.


  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    Sorry louie I don't get ya? inside the div that will refresh the content? huh?

    anyways people are saying i should have the old fashioned links too as well as the javascript so will that link anchor not get in the way?


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    anyways people are saying i should have the old fashioned links too as well as the javascript

    True - (most) search engine bots won't check for JavaScript, so they'd only find your home page and not any pages linked to....

    so will that link anchor not get in the way?

    Not as long as the function or onclick call returns false. If the JavaScript is triggered then the link won't be followed.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    Gary on IWM I gave you a link related to friendly links & javascript (ajax).
    Did you have a look at it. It explains everything Why? and How?

    The anchor # should be placed at the end of the URL+QS#top and it won't break the link at all.


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    louie wrote: »
    Gary on IWM I gave you a link related to friendly links & javascript (ajax).
    Did you have a look at it. It explains everything Why? and How?

    Started reading the first post .. and was thinking didn't Louie already say this over on IWF :D


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    Ha ya ye caught me to be honest i dont like annoying people too much so i split the questions :D

    I got the jist of it and it all seems to make sense apart from how i set up the anchor part so i dont break the link? is it javascript go to the top of the page?

    you were saying:

    <a href="link#top" onclick="jsfunction();return false;">blah blah</a>

    But i have to put in:

    <a href="http://www.ratemypub.ie/newpage.php&quot; onclick="jsfunction();return false;">blah blah</a>

    to add the old style linkage??

    louie wrote: »
    Gary on IWM I gave you a link related to friendly links & javascript (ajax).
    Did you have a look at it. It explains everything Why? and How?

    The anchor # should be placed at the end of the URL+QS#top and it won't break the link at all.


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    Oh my god Garry. You need to brush-up on your html learning curve.

    <a href="http://www.ratemypub.ie/newpage.php#top" onclick="jsfunction();return false;">blah blah</a>

    You are able to handle js but not plain html?

    http://www.w3schools.com/html/html_links.asp


  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    Ah don't think my html is that bad, I think there's a little miscommunication.

    "#top" I get that, I used to use it on the old site fine.

    The problem is, how do I use it with the javascript.

    People are saying that when they scroll to the bottom of the page and click next 20, the javascript changes the content for them but doesnt bring them back up to the top of the page.

    So the way the links are working now, if they don't have js switched on when they click next it will bring them to a new page (generally at the top anyways) but if they have js switched on when they click next it refresh the content of the page but won't change the position.

    Sorry for the confusion lads.



    louie wrote: »
    Oh my god Garry. You need to brush-up on your html learning curve.

    <a href="http://www.ratemypub.ie/newpage.php#top" onclick="jsfunction();return false;">blah blah</a>

    You are able to handle js but not plain html?

    http://www.w3schools.com/html/html_links.asp


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    You'll want something like ...
    window.scrollTo(0,0)

    or similar after your javascript finishes doing what its doing no doubt ?


  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    In fact ah . . nice wan!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    So, I'm assuming you want to set it up so that if they have JS enabled, you want to use AJAX to update the page content, but if they don't have JS enabled, you want to link them in the normal way?

    Easy enough.

    As you've clicked, the link should look something like:

    <a href="http://www.ratemypub.ie/page.php?locid=10&pagnum=2&quot; onclick="getNextPage(2);return false">

    Where getNextPage() uses AJAX to retrieve the details for the specified page. With JS enabled, AJAX will be used and "return false" will prevent the link from loading. With JS disabled, the link will load.

    Within your AJAX function, just add the following bit of code to jump the page to the top:

    document.location.href = '#top';


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    GaryCocs wrote: »
    In fact ah . . nice wan!

    All part of the service :D


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    seamus wrote: »
    document.location.href = '#top';

    damn ... even more obvious .. *hangs head*


Advertisement