Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:42:44+00:00 2026-06-05T11:42:44+00:00

I essentially know nothing when it comes to Javascript, so any help is appreciated.

  • 0

I essentially know nothing when it comes to Javascript, so any help is appreciated.

When a user is on a mobile phone, I want a div to popup with a link to my mobile website. Naturally, I don’t want the popup to show when the user is on their desktop.

My issue is that I can’t get the javascript to apply the css.

Here’s the javascript that I’m using.

<script type="text/javascript">
var isMobile = navigator.userAgent.match(/(iPhone|iPod|blackberry|android 0.5|htc|lg|midp|mmp|mobile|nokia|opera mini|palm|pocket|psp|sgh|smartphone|symbian|treo mini|Playstation Portable|SonyEricsson|Samsung|MobileExplorer|PalmSource|Benq|Windows Phone|Windows Mobile|IEMobile|Windows CE|Nintendo Wii)/i);

if(isMobile){
document.getElementById('mobile').style.display = 'block';
}
else{
document.getElementById('mobile').style.display = 'none';
}
;

</script>

This is the div:

<div id="mobile" style="left:116px; position: absolute; top: 106px;">
If you would like to visit our mobile website optimized for your device, click <a href="http://m.website.org">here</a>.</div>

Any help is appreciated. I’ve tried figuring it out myself, but I’ve hit a road block.

If you have a better, completely separate solution, that is welcome as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:42:47+00:00Added an answer on June 5, 2026 at 11:42 am

    I think you’re problem is that the javascript is being executed before the DOM (the HTML) is loaded and ready for manipulation. That code must fire after the window’s onload event fires. As usual, I’d recommend using jQuery library but I’ll give an example that doesn’t use it just so you don’t need to include it – you just have to be careful that there isn’t other javascript that needs to be ran when the event fires; its easy to accidently override it.

    Also, I would recommend keeping the div hidden by default and use JS to show it when needed.

    See it here
    http://jsfiddle.net/vmuX8/1/

    This script is safe to use with other scripts on the same page.

    In my example, I declare an anonymous (nameless) function which gets ran instantly after it is declared. That is to scope the variables inside of it so that no global variable is ever affected (except the window.onload function).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd essentially like to know the keyword that takes a user to my site,
Essentially I want to know if a specific XSD schema can be replaced by
Essentially I want to know if in VB.NET 2005 if using a sqlcommand and
I know next-to-nothing about Java's security model, including XML configuration, policy-setting, any security framework
First off, I'm a javascript noob and know nearly nothing of regex. I'm trying
Essentially I'd like to know just how compatible are the iPhone and the iPod
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
Essentially what I want to do is to apply additional CSS classes to individual
Essentially, I need to know how to make a UIWebView erase everything when you
Essentially, I would like to know what a Lisp image is? Is it a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.