Asp.net anchors and regular views on nav cannot communicate












0















Maybe not the best title, but I didn't know how to name it.



Navigation contains:




  1. Who are we?

  2. What we do?

  3. Our team

  4. Services


  5. Contact



    <ul class="list-unstyled h-100">
    <li>
    <a href="#who-are-we">Ko smo mi?</a>
    </li>
    <li>
    <a href="#what-we-do">Čime se bavimo?</a>
    </li>
    <li>
    <a href="#our-team">Naš tim</a>
    </li>
    <li>
    <a href="/page/services">Usluge</a>
    </li>
    <li>
    <a href="/page/contact">Kontakt</a>
    </li>





Numbers 1, 2 and 3 belong to view About, and as you can see, Services and Contact are Separated views.
I have jquery code that controls smooth scroll between anchors



$('a[href^="#"]').on('click', function (event) {
if (this.hash !== "") {
event.preventDefault();

var hash = this.hash;

$('html, body').animate({
scrollTop: $(hash).offset().top
}, 600, function () {

window.location.hash = hash;
});
}
});


And everything works just fine until user goes to Services or Contact view. After that, he can't come back to any of this anchors, wich is normal, because links not pointing to controller. If I put /page/about/ in front of every anchor, then I don't have smooth scroll in about page, it loads every time from begining.
Question is, is there any solution to solve this, to have anchors in nav and landing page, and other views?



Here is the link to the website, so if you don't understand me, you can try by yourself. Btw, don't click on contact, there is no view for that yet, and services is empty view, so don't be confused with style.
https://test.cherrydevelop.com



P.S. If anyone have better name for topic, you are welcome!










share|improve this question























  • I think you should put /page/about in front of those links. so it would be /page/about#what-we-do. Your problem probably has to do with that when you add /page/about to the front of your href your jquery selector a[href^="#"] breaks because the href no longer starts with (^) the hashtag (#). So change the selector to a[href*="#"], which uses * (contains) instead of ^ (starts with). Or just use a class (i.e. .scroll-link). You will also have to look for the hash on page load and scroll to it if it exists

    – zgood
    Nov 21 '18 at 20:12













  • Already tried that...It doesn't work...loads page from begining every time just on anchor...a[href*="#"] in that case don't do the job, because controller page and view about is called every time

    – mr. Panzerman
    Nov 21 '18 at 20:25











  • When I put /page/about in front of hashes, and set a[href*="#"] still cannot access from service page, but I found a solution. When I remove event.preventDefault(); from my jquery function...then it works...Thanks anyway

    – mr. Panzerman
    Nov 21 '18 at 22:17
















0















Maybe not the best title, but I didn't know how to name it.



Navigation contains:




  1. Who are we?

  2. What we do?

  3. Our team

  4. Services


  5. Contact



    <ul class="list-unstyled h-100">
    <li>
    <a href="#who-are-we">Ko smo mi?</a>
    </li>
    <li>
    <a href="#what-we-do">Čime se bavimo?</a>
    </li>
    <li>
    <a href="#our-team">Naš tim</a>
    </li>
    <li>
    <a href="/page/services">Usluge</a>
    </li>
    <li>
    <a href="/page/contact">Kontakt</a>
    </li>





Numbers 1, 2 and 3 belong to view About, and as you can see, Services and Contact are Separated views.
I have jquery code that controls smooth scroll between anchors



$('a[href^="#"]').on('click', function (event) {
if (this.hash !== "") {
event.preventDefault();

var hash = this.hash;

$('html, body').animate({
scrollTop: $(hash).offset().top
}, 600, function () {

window.location.hash = hash;
});
}
});


And everything works just fine until user goes to Services or Contact view. After that, he can't come back to any of this anchors, wich is normal, because links not pointing to controller. If I put /page/about/ in front of every anchor, then I don't have smooth scroll in about page, it loads every time from begining.
Question is, is there any solution to solve this, to have anchors in nav and landing page, and other views?



Here is the link to the website, so if you don't understand me, you can try by yourself. Btw, don't click on contact, there is no view for that yet, and services is empty view, so don't be confused with style.
https://test.cherrydevelop.com



P.S. If anyone have better name for topic, you are welcome!










share|improve this question























  • I think you should put /page/about in front of those links. so it would be /page/about#what-we-do. Your problem probably has to do with that when you add /page/about to the front of your href your jquery selector a[href^="#"] breaks because the href no longer starts with (^) the hashtag (#). So change the selector to a[href*="#"], which uses * (contains) instead of ^ (starts with). Or just use a class (i.e. .scroll-link). You will also have to look for the hash on page load and scroll to it if it exists

    – zgood
    Nov 21 '18 at 20:12













  • Already tried that...It doesn't work...loads page from begining every time just on anchor...a[href*="#"] in that case don't do the job, because controller page and view about is called every time

    – mr. Panzerman
    Nov 21 '18 at 20:25











  • When I put /page/about in front of hashes, and set a[href*="#"] still cannot access from service page, but I found a solution. When I remove event.preventDefault(); from my jquery function...then it works...Thanks anyway

    – mr. Panzerman
    Nov 21 '18 at 22:17














0












0








0








Maybe not the best title, but I didn't know how to name it.



Navigation contains:




  1. Who are we?

  2. What we do?

  3. Our team

  4. Services


  5. Contact



    <ul class="list-unstyled h-100">
    <li>
    <a href="#who-are-we">Ko smo mi?</a>
    </li>
    <li>
    <a href="#what-we-do">Čime se bavimo?</a>
    </li>
    <li>
    <a href="#our-team">Naš tim</a>
    </li>
    <li>
    <a href="/page/services">Usluge</a>
    </li>
    <li>
    <a href="/page/contact">Kontakt</a>
    </li>





Numbers 1, 2 and 3 belong to view About, and as you can see, Services and Contact are Separated views.
I have jquery code that controls smooth scroll between anchors



$('a[href^="#"]').on('click', function (event) {
if (this.hash !== "") {
event.preventDefault();

var hash = this.hash;

$('html, body').animate({
scrollTop: $(hash).offset().top
}, 600, function () {

window.location.hash = hash;
});
}
});


And everything works just fine until user goes to Services or Contact view. After that, he can't come back to any of this anchors, wich is normal, because links not pointing to controller. If I put /page/about/ in front of every anchor, then I don't have smooth scroll in about page, it loads every time from begining.
Question is, is there any solution to solve this, to have anchors in nav and landing page, and other views?



Here is the link to the website, so if you don't understand me, you can try by yourself. Btw, don't click on contact, there is no view for that yet, and services is empty view, so don't be confused with style.
https://test.cherrydevelop.com



P.S. If anyone have better name for topic, you are welcome!










share|improve this question














Maybe not the best title, but I didn't know how to name it.



Navigation contains:




  1. Who are we?

  2. What we do?

  3. Our team

  4. Services


  5. Contact



    <ul class="list-unstyled h-100">
    <li>
    <a href="#who-are-we">Ko smo mi?</a>
    </li>
    <li>
    <a href="#what-we-do">Čime se bavimo?</a>
    </li>
    <li>
    <a href="#our-team">Naš tim</a>
    </li>
    <li>
    <a href="/page/services">Usluge</a>
    </li>
    <li>
    <a href="/page/contact">Kontakt</a>
    </li>





Numbers 1, 2 and 3 belong to view About, and as you can see, Services and Contact are Separated views.
I have jquery code that controls smooth scroll between anchors



$('a[href^="#"]').on('click', function (event) {
if (this.hash !== "") {
event.preventDefault();

var hash = this.hash;

$('html, body').animate({
scrollTop: $(hash).offset().top
}, 600, function () {

window.location.hash = hash;
});
}
});


And everything works just fine until user goes to Services or Contact view. After that, he can't come back to any of this anchors, wich is normal, because links not pointing to controller. If I put /page/about/ in front of every anchor, then I don't have smooth scroll in about page, it loads every time from begining.
Question is, is there any solution to solve this, to have anchors in nav and landing page, and other views?



Here is the link to the website, so if you don't understand me, you can try by yourself. Btw, don't click on contact, there is no view for that yet, and services is empty view, so don't be confused with style.
https://test.cherrydevelop.com



P.S. If anyone have better name for topic, you are welcome!







asp.net navigation anchor smooth-scrolling






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 19:25









mr. Panzermanmr. Panzerman

698




698













  • I think you should put /page/about in front of those links. so it would be /page/about#what-we-do. Your problem probably has to do with that when you add /page/about to the front of your href your jquery selector a[href^="#"] breaks because the href no longer starts with (^) the hashtag (#). So change the selector to a[href*="#"], which uses * (contains) instead of ^ (starts with). Or just use a class (i.e. .scroll-link). You will also have to look for the hash on page load and scroll to it if it exists

    – zgood
    Nov 21 '18 at 20:12













  • Already tried that...It doesn't work...loads page from begining every time just on anchor...a[href*="#"] in that case don't do the job, because controller page and view about is called every time

    – mr. Panzerman
    Nov 21 '18 at 20:25











  • When I put /page/about in front of hashes, and set a[href*="#"] still cannot access from service page, but I found a solution. When I remove event.preventDefault(); from my jquery function...then it works...Thanks anyway

    – mr. Panzerman
    Nov 21 '18 at 22:17



















  • I think you should put /page/about in front of those links. so it would be /page/about#what-we-do. Your problem probably has to do with that when you add /page/about to the front of your href your jquery selector a[href^="#"] breaks because the href no longer starts with (^) the hashtag (#). So change the selector to a[href*="#"], which uses * (contains) instead of ^ (starts with). Or just use a class (i.e. .scroll-link). You will also have to look for the hash on page load and scroll to it if it exists

    – zgood
    Nov 21 '18 at 20:12













  • Already tried that...It doesn't work...loads page from begining every time just on anchor...a[href*="#"] in that case don't do the job, because controller page and view about is called every time

    – mr. Panzerman
    Nov 21 '18 at 20:25











  • When I put /page/about in front of hashes, and set a[href*="#"] still cannot access from service page, but I found a solution. When I remove event.preventDefault(); from my jquery function...then it works...Thanks anyway

    – mr. Panzerman
    Nov 21 '18 at 22:17

















I think you should put /page/about in front of those links. so it would be /page/about#what-we-do. Your problem probably has to do with that when you add /page/about to the front of your href your jquery selector a[href^="#"] breaks because the href no longer starts with (^) the hashtag (#). So change the selector to a[href*="#"], which uses * (contains) instead of ^ (starts with). Or just use a class (i.e. .scroll-link). You will also have to look for the hash on page load and scroll to it if it exists

– zgood
Nov 21 '18 at 20:12







I think you should put /page/about in front of those links. so it would be /page/about#what-we-do. Your problem probably has to do with that when you add /page/about to the front of your href your jquery selector a[href^="#"] breaks because the href no longer starts with (^) the hashtag (#). So change the selector to a[href*="#"], which uses * (contains) instead of ^ (starts with). Or just use a class (i.e. .scroll-link). You will also have to look for the hash on page load and scroll to it if it exists

– zgood
Nov 21 '18 at 20:12















Already tried that...It doesn't work...loads page from begining every time just on anchor...a[href*="#"] in that case don't do the job, because controller page and view about is called every time

– mr. Panzerman
Nov 21 '18 at 20:25





Already tried that...It doesn't work...loads page from begining every time just on anchor...a[href*="#"] in that case don't do the job, because controller page and view about is called every time

– mr. Panzerman
Nov 21 '18 at 20:25













When I put /page/about in front of hashes, and set a[href*="#"] still cannot access from service page, but I found a solution. When I remove event.preventDefault(); from my jquery function...then it works...Thanks anyway

– mr. Panzerman
Nov 21 '18 at 22:17





When I put /page/about in front of hashes, and set a[href*="#"] still cannot access from service page, but I found a solution. When I remove event.preventDefault(); from my jquery function...then it works...Thanks anyway

– mr. Panzerman
Nov 21 '18 at 22:17












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419233%2fasp-net-anchors-and-regular-views-on-nav-cannot-communicate%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419233%2fasp-net-anchors-and-regular-views-on-nav-cannot-communicate%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules