Why are my html links not working? - html

I am trying to link my mobile menu to different sections on the homepage. It is a one page website. The links are not working. What is wrong with my mobile menu code? Thanks!
```
<nav id="menu">
<ul>
<li class="active">Home</li>
<li>About Us</li>
<li>Services </li>
<li>Contact</li>
</ul>
</nav>
```

You need to remove index.html in your href or it will reload the page.
Set id for the element you want to link to:
About
And:
<section id="about-section">...

If everything is on one page, you can omit the page name in the link, i.e. just use
<a href="#targetabout">
instead of
<a href="index.html#targetabout">
Note: If (just in case) the linked element has the ID #about, don't use #targetabout, but just #about, like <a href="#about">

Don't include the "index.html" in the href in your links, or it will reload the page. It should just be <a href="#about">, <a href="#services">, etc. I'm not sure why you prefaced them with "target", that's not necessary. These should all correspond to <a name> tags, in the body of the page. Since this is a one-page website, and that <nav> only appears once, you don't need to keep linking to index.html.
<nav id="menu">
<ul>
<li class="active">Home</li>
<li>About Us</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
<a name="about"><h2>About Us</h2></a>
<!-- your page here -->
<a name="services"><h2>Services</h2></a>
<!-- and so on.... -->
<a name="contact"><h2>Contact</h2></a>
These <a> tags, with no href and only a name, do not visually affect their contents in any way. It's just a sort of "bookmark", to specify where on the page to jump to. For instance, you can't click on them, and they don't appear any different than regular text. You could use this, and it would work (and look) exactly the same.
<a name="about"></a> <h2>About Us</h2>
<a name="services"></a> <h2>Services</h2>
This technique also works with jumping up to the top of a page, as well as jumping down.

It is a bit late, but....
If you use jQuery mobile, this is expected behaviour (see mobile documentation). So you have to scroll to the section yourself:
<script language="JavaScript" type="text/javascript">
function getAnchor() {
return (document.URL.split('#').length > 1) ? document.URL.split('#')[1] : null;
}
function scrollTo(hash) {
if (hash){
location.hash = "#" + hash;
}
}
scrollTo(getAnchor());
</script>

Related

Anchor links just won't work

I am working on a bespoke WordPress build and for some reason, I just cannot get some anchor links to work. It's driving me potty and I just don't know what the problem is.
I have discovered, static anchor links are working fine (the back to top button works). However, I am using Advanced Custom Fields to generate ID's for the anchor tags. The IDs are generating correctly, but won't work as anchor tags.
Anyone have any ideas? The bit I am referring to is the service boxes near the bottom of the page. The idea being you click on these and that they will take you to the services page, and down to the relevant section.
The markup I am using is:
<ul class="cf">
<li>
<div>
<a href="/services/#dimensional-surveys">
<div class="filter"></div>
<img width="500" height="600" src="pexels-photo-175771-500x600.jpeg" class="attachment-feature size-feature" alt="" />
<h3>3D Dimensional Surveys</h3>
</a>
</div>
</li>
</ul>
<ul class="service-list cf">
<li id="#dimensional-surveys">
<div class="feature" style="background-image:url(pexels-photo-175771.jpeg);">
</div>
</li>
</ul>
Just remove the # from id and it will work.
<ul>
<li id="example"></li>
</ul>
I have looked at your page
The point where an ancor should jump to should have no #
You do: <li id="#dimensional-surveys">
But do just <li id="dimensional-surveys">
Fix that first and test again.
You don't want the '#' on the anchor: <li id="#example"></li> should be <li id="example"></li>

How to check if urls is already open HTML

I was working on a mini website project using django. I found bootstrap a while ago and started using some of their features. One that I really liked was the dropdown button.
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Home</li>
<li>Blog</li>
<li>Contact me</li>
</ul>
</li>
But I was having a unexpected "error"/bug. When I click on one of those buttons it will add its href to the url.
And here comes the problem. It will add the href even if the url already contains it. How can I solve this problem and where. On django scripts or with javascript?
The Problem
It looks to me like everything is behaving as it should technically, the problem is with the href target itself.
Since you have a relative link not an absolute one, it assumes it target is relative to the page you are on.
Potential Solutions
1 - Use an absolute link in this case.
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Home</li>
<li>Blog</li>
<li>Contact me</li>
</ul>
</li>
2 - Use the base tag.
This will set a root url for your website, it may cause unexpected results so check and re-check if you use this solution.
HTML Base Tag

Navbar can't open link

So i made a navbar for my one page website, all the button work and go where i want them to go but when i click on forum anything happens, this is my HTML Code :
<div class="menu">
<div class="container clearfix">
<div id="nav" class="grid_9 omega">
<ul class="navigation">
<li data-slide="1">Acceuil</li>
<li data-slide="2">A propos</li>
<li data-slide="3">Serveur</li>
<li data-slide="4">Contact</li>
<li>Forum</li>
</ul>
</div>
</div>
</div>
And this is my CSS
I share it in a ghostbin https://ghostbin.com/paste/2ctm9
I don't know what's wrong about this line <li>Forum</li> why this doesn't work ?
Here is my website http://gamenxtgen.multi-gaming.fr/
Shouldnt it be something like /forum.html? Unless your are using some .htaccess the link should contain the extension.
Try this : <li>Forum</li>
Maybe you failed the href.
This is a code you have on your site:
var links = $('.navigation').find('li');
...
links.click(function (e) {
e.preventDefault();
dataslide = $(this).attr('data-slide');
goToByScroll(dataslide);
});
The link to the forum is also in li so the preventDefault applies on it to preventing it from going to the page.
To Solve this you should define your variable more clearly (maybe add a class to it). So it does not include the link. Maybe something like
<li class="slides">Slide1</li>
<li class="slides">Slide2</li>
<li class="link">Forum</li>
var links = $('.slides');

Zurb Foundation Top Bar with simple text and links?

I'm trying to pull off the following Top Bar with Zurb Foundation.
(I'm aware of how to do this with plain HTML...trying to figure out the correct way to do it using Foundation, though.)
So you've got the title-area name on the left (which works fine), and on the right the "Hi, Joe!" is just plain text and then the "Change Settings" and "Log out" are each links (which doesn't work).
Here's what's happening when I build that out...
And here's the code I'm using...
<nav class="top-bar">
<ul class="title-area">
<li class="name"><h1>Acme Company</h1></li>
<li class="toggle-topbar"></li>
</ul>
<section class="top-bar-section">
<ul class="right">
<li>Hi, Joe!</li>
<li>
Change Settings | Log out
</li>
</ul>
</section>
</nav>
So how can I get Foundation to work with my original design example above?
Foundation uses the a tag to style it. You're better off putting them in two separate li tags.
e.g.
<li><a href='#'>Change Settings</a></li>
<li class='divider'></li> <!-- built into foundation -->
<li><a href='#'>Log out</a></li>
Your Hi, Joe! should go in a blank a tag also.

Why is jQTouch not working out of the box for my HTML?

I'm new to jQTouch -- it's pretty awesome -- but I'm finding that I'm not able to get it to work out of the box for my HTML, even though I'm following the getting started guide as well as the markup guidelines.
Specifically, each of my screens is a <section> element (direct child of <body>) with a unique ID, and I have links to those IDs, e.g. <a href="#screen-a">. This seems to follow the convention of the demo code, but yet the demo code works and my code doesn't.
Here is the HTML structure of my <body>:
<section id="main-menu">
<header class="toolbar"><!-- ... --></header>
<nav>
<ul>
<li class="arrow">Screen A</li>
<li class="arrow">Screen B</li>
<li class="arrow">Screen C</li>
</ul>
</nav>
<footer><!-- ... --></footer>
</section>
<section id="screen-a"><!-- ... --></section>
<section id="screen-b"><!-- ... --></section>
<section id="screen-c"><!-- ... --></section>
<script src="jquery.min.js"></script>
<script src="jqtouch.min.js"></script>
<script src="init.js"></script>
And my init.js simply initializes jQTouch (no custom options):
var jQT = new $.jQTouch({});
When I load my page, the UI appears fine, and I can confirm jQTouch was initialized because my jQT variable exists.
But when I click any link, the location bar changes to the new hash (e.g. "#screen-a"), but the UI doesn't change. And the JavaScript console starts throwing repeated multiple No pages in history errors.
(When I use the unminified jQTouch.js, these errors come from inside the jQTouch goBack() function, which is being called from the dumbLoopStart() timer.)
Note that this happens for me both in desktop Safari and in Mobile Safari on the iPhone. But that's very strange, because their demo works just fine for me on both.
I've banged my head against this for hours to no avail. Does anyone have ideas or suggestions or tips for what I might be doing wrong? Thanks!
I created an test from your provided example (with the addition of the style imports). Simply removing the <nav> elements resolved the issue for me.
I believe your main elements have to be div's. Additionally, you need a class of "current" on the div that should be displayed first.
I don't know if the version you are using requires this, but what I pulled via git a while back requires that all of your main elements be contained in a div with an id of "jqt".
<div id="jqt">
<div id="main-menu" class="current">
<ul>
<li class="arrow">Screen A</li>
<li class="arrow">Screen B</li>
<li class="arrow">Screen C</li>
</ul>
</div>
<div id="screen-a"><!-- ... --></div>
<div id="screen-b"><!-- ... --></div>
<div id="screen-c"><!-- ... --></div>
</div>
<script src="jquery.min.js"></script>
<script src="jqtouch.min.js"></script>