Create link to another page’s menu item

Asked

Viewed 59 times

1

hello, I have the following page with a service menu in the middle of it as follows:

http://www.clinvetimbituba.com.br/servicos.html

ond and when I click on a service changes the content on the right side, ok.

as I create on another page links that open this service page already direct in the services.

att

Richardy

1 answer

0


You can put a hash #servicosN (where N is the link number) in the URL and use window.scrollTo to scroll the screen to the menu and fire a click in the menu link. Example of the link:

http://www.clinvetimbituba.com.br/servicos.html#servicos1

And put this script on the page servicos.html:

document.addEventListener("DOMContentLoaded", function(){
   var target = location.hash; // verifica se tem hash na URL
   var linq = $("ul.nav-tabs li a[href$='"+target+"']"); // link que contém a hash
   if(target && linq.length){
      setTimeout(function(){
         // distância do menu ao topo menos altura do nav
         var top = $(".sidebar").offset().top - $("#main-nav").height();
         window.scrollTo(0, top); // rola atela até o menu
         linq.trigger("click"); // dispara o clique
      }, 500);
   }
});
  • then, I appreciate the attention, but in fact what I need is to have a link that opens the service page already with the selected service open, for example if I am on the home page and put a link to the "service 2" there in case load the service page already with the "service 2' active

  • I know... I can do that, but see if the code above already solves a part.

  • ball show, function straight, now just need to see how to open the page already in the specific service

  • Blz... This first part working is already important. Now I will do the second part.

  • What would the default URL look like? For example, the hash #servicos scrolls the screen to the menu, and the menu link? Type: http://www.clinvetimbituba.com.br/servicos.html#servicos,link1

  • I think more or less that same type clinvetimbituba.com.br/servicos.html#service1 clinvetimbituba.com.br/servicos.html#service2 . . . clinvetimbituba.com.br/servicos.html#service10

  • See now if it works.

  • 1

    sensational, worked perfectly, without words to thank the time and effort spent in helping. how much I owe you even rssss very grateful, att Richardy

  • Cool guy! see if you can thank marking in the answer. Abs!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.