0

I'm struggling to get the contact ref to work from different pages. Basically for every product a different detail reference is provided (see 4867820 below).

I would like to create a button which links to the #contact id for every page on the website.

Basically if I put a link on the button including the reference, this works perfectly.

http://www.mywebsite/product/4867820#contact

However I am wondering if I can create something similar where the button links to the contact id on the same page without using the reference number.

http://www.mywebsite/product/this page#contact

So basically my question is how do I link to only #contact on this page without the reference numbers, so I can create 1 button on the page template.

Regards,

  • Do you link to the same page that the button is on? – Sergio Tulentsev Apr 26 '17 at 13:03
  • you need to use something like `php` to store that referce number inside a variable , this can be done in the session or on database level. If you have a variable its pretty easy : `http://www.mywebsite/product/ . $product->id . #contact` – Christophvh Apr 26 '17 at 13:11

1 Answers1

0

Assuming it will always point to the same page as the button:

a) If you are able to use anchor tags instead of buttons (and CSS-style them to look like buttons), you can simply point the anchor's href attribute to the section name.

It works like a relative link, just appending the href to current URL. Like so:

<a href="#contact">Contact Here</a>

Or b) if you have to use only a <button> or <input> element specifically, you will need to use javascript to set the location in onclick handler of the button. For details on that see: Javascript inline onclick goto local anchor

Community
  • 1
  • 1
Vasan
  • 4,810
  • 4
  • 20
  • 39