Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Named anchor tags don't work?


paulm2003

Recommended Posts

Normally when I use a named anchor tags like this:

<a href="#tips">Jump to the Useful Tips Section</a>

It jumps to the named tag

<a name="tips">tips</a>

on the same page.

 

but in osCommerce for some reason it does not work, it only works if I use for example:

<a href="faq.php#tips">Jump to the Useful Tips Section</a>

 

Does anybody know why? :unsure:

It seems to me that this last solution makes the whole page load again, which I obviously don't want to happen, only want it to jump to the named tag inside the current page.

Link to comment
Share on other sites

  • 10 months later...
Normally when I use a named anchor tags like this:

<a href="#tips">Jump to the Useful Tips Section</a>

It jumps to the named tag

<a name="tips">tips</a>

on the same page.

 

but in osCommerce for some reason it does not work, it only works if I use for example:

<a href="faq.php#tips">Jump to the Useful Tips Section</a>

 

Does anybody know why?  :unsure:

It seems to me that this last solution makes the whole page load again, which I obviously don't want to happen, only want it to jump to the named tag inside the current page.

QUOTE(Red3D @ Nov 27 2004, 07:04 PM)

 

 

PHP pages are dynamic and will reload unlike static HTML files - but you must consider sessions when you code links in OSCommerce - see the following:-

 

Hi this is a reply to another post but may help you,

 

I have just sussed a fix for my site using ancor tags and also using the session ID in the header.

 

use the echo tep_href_link like this to link to a page in the static information pages (there is a function to ref to product pages but I'm unsure if it will accept the following code:-

 

<?php echo tep_href_link( "reference_rigs5.php"); ?>#spinning

 

NOTE - add the #anchor tag outside the php echo tep_href_link code and this will maintain the session ID whilst providing an HTML style anchor to wherever on the page you want the link to point to ! (in this case "#spinning")

 

In OSC sessions it merely adds it after the OSCid and maintains the session.

 

I tried many things to get this to work, but if like me you have avoided using cookies etc then this definitely works !

 

I'll be watching this thread so any comments or problems please feed back !

 

Regards

 

 

 

Jeremy

 

 

:D

Link to comment
Share on other sites

QUOTE(Red3D @ Nov 27 2004, 07:04 PM)

PHP pages are dynamic and will reload unlike static HTML files - but you must consider sessions when you code links in OSCommerce - see the following:-

 

Hi this is a reply to another post but may help you,

 

I have just sussed a fix for my site using ancor tags and also using the session ID in the header.

 

use the echo tep_href_link like this to link to a page in the static information pages (there is a function to ref to product pages but I'm unsure if it will accept the following code:-

 

<?php echo tep_href_link( "reference_rigs5.php"); ?>#spinning

 

NOTE - add the #anchor tag outside the php echo tep_href_link code and this will maintain the session ID whilst providing an HTML style anchor to wherever on the page you want the link to point to ! (in this case "#spinning")

 

In OSC sessions it merely adds it after the OSCid and maintains the session.

 

I tried many things to get this to work, but if like me you have avoided using cookies etc then this definitely works !

 

I'll be watching this thread so any comments or problems please feed back !

 

Regards

Jeremy

 

 

:D

 

 

remove the <BASE HREF statement which is in every page.

I had the same problem, removed it and voila !

Treasurer MFC

Link to comment
Share on other sites

remove the <BASE HREF statement which is in every page.
Hmm.. stil not sure what the BASE HREF is good for, never used it before I entered the oscommerce world, but it might be there for a good reason.

 

You can also work around this problem by using this:

<a href="<?php echo $_SERVER['REQUEST_URI']; ?>#top">Top</a>

Works like a normal anchor tag (so without reloading the whole page), the session is retained, and you can keep the BASE HREF.

 

 

 

@Jeremy: using the tep_href the whole page is reloaded after every click, or isn't it?

 

@Amanda: You remind me, I have got to work on my languages switch :D

Link to comment
Share on other sites

Easy, for instance in faq.php

......

Hi John, sorry but the solution you propose here has already been mentioned at the top of this thread, but it does not work as we would like, because it makes the whole page reload!

While one of the nice things about those anchors is, that it's not needed to reload the page. (Which saves me some bandwith and the customers some time)

Link to comment
Share on other sites

Hi John, sorry but the solution you propose here has already been mentioned at the top of this thread, but it does not work as we would like, because it makes the whole page reload!

While one of the nice things about those anchors is, that it's not needed to reload the page. (Which saves me some bandwith and the customers some time)

Hi Paul,

Oops I see I read to fast :)

Anyway OP started with faq and I see no reason for a page called faq.php not to do it the way we both like, no reload is IMO good in that case :)

"If you're working on something new, then you are necessarily an amateur."

Link to comment
Share on other sites

  • 4 months later...
Has anyone got any further suggestions on how to make anchors work properly, especially on dynamic pages where you can't just add the appropriate HTML. Obviously the session ID needs to be retained.

 

Expalin it to me please, I'm a complete idiot when it comes to PHP.  :-"

 

 

I use this function : add to html_output.php

 

function tep_sp_link ($name) { // same page link

 

global $request_type;

 

if ($request_type == 'SSL') {

$link = HTTPS_SERVER . DIR_WS_HTTP_CATALOG;

} else {

$link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;

}

 

$uri = str_replace('/','',getenv(REQUEST_URI));

 

return $link . $uri . '#' . $name;

}

 

 

then for the link I use :

 

<td align="right"><a onmouseover="window.status='Top'; return true" href="<?php echo tep_sp_link('top'); ?>"><img src="images/button_top.gif" border="0" alt="top" title="top"></a></td>

Treasurer MFC

Link to comment
Share on other sites

  • 2 weeks later...

Thank you very much to boxtel for helping me out on this. Here are the important points she helped me with:

 

boxtel: You cannot add php code to the product description in admin.

 

ok, this should work :

 

in html_output.php you add this new function :

 

function tep_sp2_link () {

global $request_type;

if ($request_type == 'SSL') {$link = HTTPS_SERVER ;}

else {$link = HTTP_SERVER ;}

$uri = $_SERVER['REQUEST_URI'];

return $link . $uri;

}

 

 

then in products_info.php you have this statement :

 

echo stripslashes($product_info['products_description']);

 

that statement puts your description on the page.

 

just before that statement you add this :

 

// start anchor same page link

$anchor_link = tep_sp2_link();

$product_info['products_description'] = str_replace('[sp2link]', $anchor_link, $product_info['products_description']);

// end anchor same page link

 

this basically looks in your text to find the link [sp2link] and replaces that with the real page link including parameters and sid if present.

 

then in your product description in your admin you write the links like this :

 

See this link <a href="[sp2link]#top">for more information.</a>

go to our <a href="[sp2link]#business">Business section</a>

 

etc.

 

You can ofcourse change the link to whatever you like for example *anchor* or @anchor as long as you make sure that that text does not appear in your normal text otherwise the program would replace that as well. so make it something that would normally not be in your product description.

 

 

let me know if it works ok

 

This all worked, thank you boxtel. :D

Link to comment
Share on other sites

Thank you very much to boxtel for helping me out on this. Here are the important points she helped me with:

This all worked, thank you boxtel.? :D

 

Also, the Session IDs are retained.

 

I have to make a slight change as I want the osCommerce files to be in the root directory not in the "catalog" directory. This is because Search Engines will give you a better position if the pages are closer to the root. :)

Edited by Thomas_Burke
Link to comment
Share on other sites

  • 1 month later...
Also, the Session IDs are retained.

 

I have to make a slight change as I want the osCommerce files to be in the root directory not in the "catalog" directory. This is because Search Engines will give you a better position if the pages are closer to the root.  :)

I installled the contribution Anchor Tag. This work fine, but i have the name of product or categorie in header.php and in footer.php. I want installed in this files and don?t work. I want adapt this contribution ?Can you help me?

Thanks

Tienda de informatica online. Venta de ordenadores. Venta de port?titles

Link to comment
Share on other sites

  • 2 months later...
I use this function : add to html_output.php

 

function tep_sp_link ($name) {? // same page link

 

? global $request_type;

 

if ($request_type == 'SSL') {

? $link = HTTPS_SERVER . DIR_WS_HTTP_CATALOG;

} else {

? $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;

}

 

$uri = str_replace('/','',getenv(REQUEST_URI));

 

return $link . $uri . '#' . $name;

}

then for the link? I use :

 

? ? ? ? <td align="right"><a onmouseover="window.status='Top'; return true" href="<?php echo tep_sp_link('top'); ?>"><img src="images/button_top.gif" border="0" alt="top" title="top"></a></td>

 

I just did a search for anchor tags and found this and it doesnt quite work properly because I think our store is in a directory and Boxtel`s isnt.

Using the above gives us a reloaded page with a url similar to...

www.oursite.com/shopshopcurrentpage.php (ie the shop directory seems to be doubled up)

Ive tried playing about a bit but cant quite figure it out :blush:

Can anyone be so kind to help me out please?

Edited by Reesy
Link to comment
Share on other sites

I adjusted the code in html_output.php and product_info.php as suggested above in this thread. I'd thought to be able to use it in my FAQ page, where topics at the top of the page link down to anchors further down on the same page.

 

<a href="[sp2link]#Anchor-What-49575">What is included in your services?</a>

takes me to a "404 Not Found" error page.

 

I did add code to the faq.php page that is similar to the code added to the product_info.php page, with no change.

 

Ideas?

Link to comment
Share on other sites

I adjusted the code in html_output.php and product_info.php as suggested above in this thread. I'd thought to be able to use it in my FAQ page, where topics at the top of the page link down to anchors further down on the same page.

 

<a href="[sp2link]#Anchor-What-49575">What is included in your services?</a>

takes me to a "404 Not Found" error page.

 

I did add code to the faq.php page that is similar to the code added to the product_info.php page, with no change.

 

Ideas?

 

PandA.nl`s code workded for me

Link to comment
Share on other sites

I just did a search for anchor tags and found this and it doesnt quite work properly because I think our store is in a directory and Boxtel`s isnt.

Using the above gives us a reloaded page with a url similar to...

www.oursite.com/shopshopcurrentpage.php (ie the shop directory seems to be doubled up)

Ive tried playing about a bit but cant quite figure it out  :blush:

Can anyone be so kind to help me out please?

 

try this instead:

 

$uri = substr(getenv(REQUEST_URI), 1);

Treasurer MFC

Link to comment
Share on other sites

I adjusted the code in html_output.php and product_info.php as suggested above in this thread. I'd thought to be able to use it in my FAQ page, where topics at the top of the page link down to anchors further down on the same page.

 

<a href="[sp2link]#Anchor-What-49575">What is included in your services?</a>

takes me to a "404 Not Found" error page.

 

I did add code to the faq.php page that is similar to the code added to the product_info.php page, with no change.

 

Ideas?

 

go to your faq page, view the source and check what the links look like.

Treasurer MFC

Link to comment
Share on other sites

  • 1 year later...
  • 5 months later...
  • 2 months later...

Hi Guys,

I really suck at php and just need to know how the actual code would look when adding this...

 

then in products_info.php you have this statement :

 

echo stripslashes($product_info['products_description']);

 

that statement puts your description on the page.

 

just before that statement you add this :

 

// start anchor same page link

$anchor_link = tep_sp2_link();

$product_info['products_description'] = str_replace('[sp2link]', $anchor_link, $product_info['products_description']);

// end anchor same page link

Link to comment
Share on other sites

  • 2 weeks later...
Hi Guys,

I really suck at php and just need to know how the actual code would look when adding this...

 

then in products_info.php you have this statement :

 

echo stripslashes($product_info['products_description']);

 

that statement puts your description on the page.

 

just before that statement you add this :

 

// start anchor same page link

$anchor_link = tep_sp2_link();

$product_info['products_description'] = str_replace('[sp2link]', $anchor_link, $product_info['products_description']);

// end anchor same page link

 

Well I just got here from Google on your code.

Any idea how I can add chunks of text I'm importing in multiple fields?

 

This has no errors shown, but still doesn't display products_description2.

		  <p><?php echo stripslashes($product_info['products_description']); ?></p>
	  <p><?php echo stripslashes($product_info['products_description2']); ?></p>

Should I put both ['products_description''products_description2'] in the brackets?

Link to comment
Share on other sites

  • 3 years later...

You can also work around this problem by using this:

<a href="<?php echo $_SERVER['REQUEST_URI']; ?>#top">Top</a>

Works like a normal anchor tag (so without reloading the whole page), the session is retained, and you can keep the BASE HREF.

Thank you PandA.nl! I found this page through Google, and this was the simplest fix. Thanks for the help!

Link to comment
Share on other sites

  • 4 weeks later...

Just installed and it changes the links as expected; <a href="[sp2link]#whatever">Link</a> does give longfile.php#whatever but then it says 'file not found' when clicked. I tried <p id="#whatever> and <a name="whatever">, am I doing it wrong??

 

Can anyone explain how to get it working on categories pages too? I looked through index.php but can't see what to change.

Edited by powerdrive
Link to comment
Share on other sites

  • 4 years later...

Hmm.. stil not sure what the BASE HREF is good for, never used it before I entered the oscommerce world, but it might be there for a good reason.

 

You can also work around this problem by using this:

<a href="<?php echo $_SERVER['REQUEST_URI']; ?>#top">Top</a>

That works perfectly!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...