Anchors

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

Anchors

Post by tyman00 »

I had some issues with HTML anchors not working properly. They would default to index.php#Anchor insead of /index.php?page=Name#Anchor

I wrote a Javascript solution that helped me out and I thought I would share. I am actually using it with pretty url's (domain.com/parent/child#Anchor).

Use the attached JS file (remove the .txt extension). You can either reference the in your template or in specific pages. I did not include it in my Template. I am putting it in the Metadata field under the options tab on just the pages that I am using anchors, with the following code:

Code: Select all

{literal}
<__script__ src="/JS/anchor.js" type="text/javascript"></__script>
{/literal}
To get the anchors to work you need to call the anchor function and pass the anchor name within the function call. Here is how I did it.

Code: Select all

<a href="javascript:anchor('#Top');">^Top</a>
You would replace #Top with your anchor name. Be sure to include the Hash Mark (#) in your anchor name.

I tested it in IE 6, IE 7, Avant 11, Netscape 8.1 (A little buggy), and Firefox 2
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

Last edited by tyman00 on Mon Jun 11, 2007 5:13 pm, edited 1 time in total.
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
User avatar
pixelita
Power Poster
Power Poster
Posts: 388
Joined: Sun Sep 16, 2007 3:07 am

Re: Anchors

Post by pixelita »

Hmm. I had high hopes for this but I am getting Smarty errors.  This is such a great CMS, but there are a few stumbling blocks and they are annoying, this being one of them. 

UPDATE:  I reluctantly added the JS to the template head and all seems to be fine now. Thanks a bunch!!
Last edited by pixelita on Sun Sep 23, 2007 1:36 am, edited 1 time in total.
Submit your site to the We Love CMSMS showcase
Post Reply

Return to “Tips and Tricks”