Anchor positioning within Firefox Mobile (for Android)

I created a homepage with multiple sections, each linked to from the main menu:

<body>
    <header>
        <!-- nav used on all pages -->
        <a href="#nav" class="toggle-nav">
            menu <i class="fa fa-bars"></i>
        </a>
        <nav class="main-nav" id="nav">
            <a href="/#item1">Link</a>
            <a href="/#item2">Link</a>
        </nav>
    </header>


    <!-- homepage -->
    <main>
        <section id="item1">some content here </section>
        <section id="item2">some other content here </section>
    </main>
</body>

Maybe this css is relevant:

body {
    position: relative;
    overflow-x: hidden;
}

@media only screen and (max-width: 750px) {
    header .main-nav a {
        display: block;
    }

    .tiggle-nav {
        display: none;
    }
}

The goal is for users to click on 'Item 1' in the menu and be taken directly to that section of the homepage.

This setup works perfectly, except on firefox mobile. When clicking the internal anchor link from any other internal page, the homepage loads anywhere from 100 to 200px off the mark.

Interestingly, refreshing the page after initially loading allows firefox mobile to find the internal anchor correctly. This issue seems exclusive to navigating from an internal page to the homepage.

What could be causing this problem? Is there a delay in loading CSS on firefox mobile until it locates the internal anchor?

Most importantly, how can I ensure firefox mobile lands on the correct location right away?

Any insights would be greatly appreciated.

View the full css and html live at

Answer №1

To fix the issue, modify the main.js file by changing 400 to 0 in the section below:

$('#top').click(function(e) {
    e.preventDefault();
    $('body,html').animate({scrollTop:0},400);
});

After the adjustment, the code should appear as follows:

$('#top').click(function(e) {
    e.preventDefault();
    $('body,html').animate({scrollTop:0},0);
});

I have tested this change and it appears to resolve the problem. The likely reason for this is that the extra 400 pixels previously added above the anchor link are no longer included.

Answer №2

To replicate the issue, I followed these steps:

First, I navigated to the connect page and selected "Writing". The positioning was off at this point. Next, I turned off JavaScript so that the anchor could be relied upon for navigation, which resolved the issue.

In order to address this issue in a more permanent way, I implemented a solution where a specific element on the page is identified to determine whether to use JavaScript scrolling or direct anchoring.

if (document.getElementById('homepagebookmark')){
  //scroll with JavaScript
} else {
  //maintain current behavior
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble aligning material-ui GridList in the center

I am currently working with a GridList in order to display Cards. The styling for these components is set up as shown below: card.js const useStyles = makeStyles({ card: { maxWidth: 240, margin: 10 }, media: { heigh ...

Easy jQuery image that smoothly fades in and out

Can anyone recommend a script that allows for creating a slideshow where images fade in and out, rather than sliding left and right? I have a list of images below that I would like to use for the slideshow. <ul class="slideshow"> <li><im ...

Ensure that every HTML link consistently triggers the Complete Action With prompt on Android devices

After extensive searching, I have yet to find a solution to my issue. I have been developing a web application that allows users to play video files, primarily in the mp4 format. Depending on the mobile browser being used, when clicking the link, the vide ...

Tips for arranging HTML image sources to prepare for future updates

Incorporated into the HTML are a series of images, each accompanied by text and/or transitions. To streamline positioning, each image set along with other elements (text, video, etc...) is enclosed within a div. Furthermore, every image is labeled with a n ...

Tips for integrating PHP with HTML5 while developing a Blackberry native application that utilizes Blackberry websockets

I'm currently working on a basic HTML5 page that includes inline PHP script. I'm looking for advice on how to transform this app so it can be used with Blackberry WebSockets. For example, I want to develop a native app using HTML5. ...

Incorporating HTML content in email messages using a PHP mailer script

I have been exploring a way to incorporate HTML code into the email body using an AJAX PHP Form Mailer I discovered on this website: However, whenever I try to add my own HTML coding into the email body, it just displays the tags instead of rendering them ...

Changes influencing independent div elements

My goal is to design a front-end screen with images labeled steps 1-4 lined up next to each other. The concept is that when the user hovers over one of these steps, the corresponding image should fade in below them in a separate div. Upon removing the curs ...

submit content to an iframe on a separate webpage

Work has been a challenge for me lately as I try to achieve a specific task. The starting page features a textbox and a button. My goal is to post the value entered in the textbox to an iframe on a different web page called iframeholder. The catch is tha ...

Launch the jQuery Fancybox on a separate webpage

I am facing an issue where I have a link in my index.html page and I need it to open a div located in another page named index2.html, but for some reason, it is not working. This is the code I currently have: Link in index.html <a href="#modal" id="o ...

Retrieve all data points if both latitude and longitude are present in the XML dataset

XML data to retrieve details <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <results> <result> <Country_Code>IN</Country_Code> <Country_Name>India</Country_Name> <Region_Nam ...

Comparing Django forms to conventional forms

As I work on my Django website, I find myself torn between utilizing Django-Forms and sticking with the traditional hand-coded HTML forms. While HTML forms offer certain benefits that align with my needs, I must admit that I have also experienced advanta ...

Top Method for Incorporating Syntax Highlighting into Code Blocks - React Sanity Blog

I'm currently exploring the most effective method to incorporate syntax highlighting into my react sanity.io blog. Here's a look at the article component I've developed using react: import React, {useEffect, useState} from "react"; import ...

Adjust the text input width appropriately for the cloze exercise

My JavaScript-generated fill-in-the-blank text is causing me trouble when it comes to adjusting the size of the input boxes. Unlike others, I know exactly what the user will or should be entering. If there is a blank space like this _______________, I wa ...

The HTML document is having trouble establishing a connection with socketio

I currently hold an HTML file within my local file system, presented as follows: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example of a Minimal Working File</title> ...

The menu item is having trouble aligning to the right side

Hello, I am currently working on developing a website menu for a project and I am facing an issue with aligning the "Login" Menu item to the right side. Any assistance in resolving this alignment issue would be greatly appreciated. I am also willing to pro ...

The embed video is camouflaged within the bootstrap mobile display

I am currently using the latest version of bootstrap and bootswatch united theme to build and explore a standard website. The website is live at this link live site, featuring an embedded section on the right side as shown. My choice for the view engine is ...

Is there a way to restore a minimized min.css file?

Recently, I attempted to utilize an online tool for unminifying my CSS code. However, when I replaced the minified code with the unminified version and accessed the URL, I discovered that the entire website had lost its layout. Unfortunately, relying sole ...

What is the method for utilizing the variable from express in HTML?

Currently, I am working with Express and have the following code: app.get('/', requiresAuth(), (req, res) => res.sendFile('/db_auth_site/index.html', { title: 'Hey', message: 'Hello there!' }) ); I am trying ...

Is there a difference between innerHTML strings and their corresponding strings in JavaScript?

I am facing an issue with a code snippet that seems to have an unusual error. The following code is a simplified version to demonstrate the strange behavior. <html> <head> <script type = "text/javascript"> window.onload = fun ...

Having trouble interacting with element - Selenium WebDriver is not allowing the click

I'm attempting to select the Checkout Button. This is what it looks like : https://i.stack.imgur.com/TiMEO.png And here's the HTML snippet for it : <div id="buy-button-next"> <span data-reactroot=""> <div data-cid="buy- ...