Harnessing the power of Div tags with a href attribute as placeholders for interactive menu items

I am facing an issue with multiple divs covering different portions of a menu on a background image of a webpage.

Each div contains an anchor tag linking to another page and playing a click sound upon clicking.

To ensure the cursor changes across the entire div, I used a CSS technique. Check out the code snippet below:

<script language="javascript" type="text/javascript">
  function playSound(soundfile) {
      "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
  }
</script>     

<div id="apWelcome">
   <a href= "#" class="fill-div" onclick="playSound('Sounds/click.ogg');"> </a>
</div>

Here is the CSS styling for apWelcome and filling out the area:

#apWelcome {
cursor: pointer;
position: absolute;
left: 104px;
top: 216px;
width: 49px;
height: 66px;
}

a.fill-div {
cursor: pointer;
    display: block;
    height: 100%;
    width: 100%;
    text-decoration: none;
}

The challenge I'm facing is that in Firefox 24, the click behavior works fine but there's no sound. In Chrome, the sound plays but the page jumps down visually. Internet Explorer does not show the cursor or functional behavior.

If anyone has a workaround that works across all three browsers or a completely different method, please share. Thank you.

Answer №1

Take a look at this informative article discussing the use of sounds in HTML, including cross-browser compatibility. Different browsers support different types of sound files.

Additionally, you can simplify your code by directly calling your function from the `div`'s `onclick` attribute without using the `a` tag as a placeholder. Using `cursor:pointer;` will make it seamless for users.

For a comprehensive solution, refer to this Fiddle: http://jsfiddle.net/avrahamcool/ybxBq/

Answer №2

I have completely reconstructed the layout from scratch. You can access the new version for download here (The link will remain active for one week). I felt it was necessary for me to start fresh, even though it might not have been required.

  1. I opted to use an img in the BackgroundContainer rather than CSS background, ensuring that if someone prints the page, the background is still visible.
  2. The 'Site' now has fixed height and width, while its content is set in percentages for scalability when the site's size changes.
  3. If testing in IE, make sure to run the HTML from a server instead of a local file to prevent any script interruptions by the browser.
  4. I removed most of your scripts, so please reinsert them gradually, checking each time to ensure the page functions properly across all browsers.
  5. Note that I have modified some class names and file names, so review your scripts and CSS files accordingly (I also reorganized the Image folder).
  6. This new version has been tested on IE10, Firefox, and Chrome.
  7. Pay attention to the dummy URL as the background-image for clickable elements.

Best of luck with the updates.

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

Error: The symbol $ is not recognized

This is a snippet of code that I've written to automate address filling and extract latitude/longitude/address information. <html> <head> <LINK rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" sr ...

Why does the Select2 Drop down eliminate the mandatory border color?

Within my application, I have implemented a feature where required fields are designated with a red border. To achieve this effect, I utilized the following CSS code: input[data-val-required], select[data-val-required] { border: 1px solid #EFA4A4 !imp ...

Is there a way to implement tab functionality in jQuery UI through an onclick event?

My goal is to enhance an existing jQuery UI Tab container by adding tab information and then updating the contents through re-initialization. To see a demonstration of what I am trying to achieve, take a look at this JSFiddle: http://jsfiddle.net/dmchale9 ...

Utilizing AJAX and PHP for dynamic changes based on listbox selection

Is there a way to make the query run whenever a selection is made from the listbox? if(isset($_POST['select'])){ $newselection=$_POST['select']; $query = "SELECT count(*) FROM listings where description=" . $newselection. ""; $r ...

The date selector is failing to accurately reflect changes in the date objects

I've integrated a date-time picker from this source https://github.com/DanielYKPan/date-time-picker to manage 'beginning' and 'end' date objects (refer to selectedMoments in the TypeScript code) for a date selector. However, when I ...

The HTML unit is unable to locate the form for unknown reasons. My suspicion is that it could be due to the presence of Angular

Struggling with using HTMLunit to login and upload a file. Successfully logged in but unable to locate the form, despite it being present on the HTML page. Here is the JAVA CODE snippet: public static void main(String[] args) { WebClient webClient = ...

The request to remove the product from the server at URL http://localhost:8000/product/[object%20Object] encountered an internal server

I'm having trouble setting up the AJAX delete method. I keep getting a 500 internal server error and despite following tutorials, I remain frustrated. Can someone please help me correct my code? This is using Laravel 5.8 and jQuery 3.3. <section ...

Building with bricks and mortar does not involve organizing visual content

I'm currently trying to organize some fairly large images using masonry, but the code below doesn't seem to be working. I'm using node.js with express and have installed the masonryjs package in an attempt to make it work, but that approach ...

Convert the string to a time format of hours and minutes (hh:mm)

I am currently working with an input field that requires a time value to be entered. The format for the Time field is in hh:mm on the 24-hour clock format, such as 7:30, 11:45, 16:10, 19:11, or 22:43. <input id="szReminderTime" type="text" value="" max ...

Is there a simpler method to enable built-in CSS-Sass in Next.js without the need for excessive configuration?

Is there a way to maintain the built-in CSS/SASS feature in Next.js without extensive configuration? Utilizing the built-in CSS/SASS is convenient, but introducing less to next.config.js triggers the disabling of this feature, requiring manual configurati ...

Which is the preferable option for creating a circular daily planner: canvas or SVG?

As a novice programmer delving into the world of coding (or at least hoping to), I have a question regarding graphic tools in html5 for my latest project. My goal is to create a planner app using electron, with the unique twist that the planner form sho ...

Unable to modify the link color within a Bootstrap 4 button

I am facing an issue with trying to change the default link color in bootstrap 4 and sass. Below is the code snippet I am using to override the _variables.scss defaults: $body-bg: #f4f4f4; $body-color: #c0b283; $link-color: #c0b283; $link-hover-decoration ...

Trouble with updating scope values in the view within IONIC 1 and AngularJS

I recently implemented a feature to save the two most recent login details. The functionality works correctly, but I'm facing an issue where my view only updates upon refresh even though the scope values are being updated. I've tried using $scop ...

Interactive phone photo gallery

I am looking to create a mobile webpage that allows me to swipe my finger left or right in the middle of the page to scroll between images. Here is an example photo: I want to be able to swipe through the images with my finger. Any suggestions on how I ...

Mobile devices offer a seamless vertical scrolling experience

Here is the HTML structure I am working with: <div> <a>..</a> <i>..</i> <a>..</a> <i>..</i> <a>..</a> <i>..</i> </div> On larger screens, all elements are dis ...

Struggling to implement a sidebar in HTML using jQuery and running into issues?

I am struggling to create a template that includes a navbar, sidebar, and other elements that can be used across multiple HTML files. Despite trying different approaches, including changing the jQuery version and downloading jQuery, I am unable to make it ...

Issue with displaying text and aligning content to the left or right in tables on mobile devices

Looking to design a table using Bootstrap and include some pull-left and pull-right content in a column? Check out this code snippet: http://jsfiddle.net/Zoker/sgdfgkvL/ <td> <div class="pull-left">Some content</div> <div cla ...

Trouble with padding in Twitter bootstrap

I am puzzled as to why the navigation links at the bottom of my page ("prev" and "next") are wider than the post teasers in my #bloglist above. I am currently utilizing twitter bootstrap with their provided scaffolding. Any insights or recommendations wou ...

Having trouble with positioning elements next to each other using Bootstrap4 list-inline

I am currently tackling the challenge of building a "Quote Machine" as part of my freeCodeCamp projects. My goal is to create a list that contains three list items functioning as buttons, lined up next to each other using the Bootstrap class "in-line." How ...

What could be causing the glitch in my Bootstrap 5.x dropdown and tooltip combination?

Whenever I hover over my icon, the tooltip is glitching and displays in the wrong place before getting stuck until I refresh the page. Check out my JSFiddle This is what I currently have implemented: HTML: <div class="dropdown"> <di ...