Is it possible to automatically navigate to a different webpage upon clicking anywhere on the background?

I have created a website with a gif background and I want to redirect to another site (like softlaunch) after clicking anywhere on the screen.

This is my HTML and CSS:

body {
  background: url(main.gif) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  background-color: #000000;
  width: 100%;
  height: 100%;
}
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <link rel="shortcut icon" type="image/png" href="fav.png" />
  <link href="style.css" rel="stylesheet" type="text/css">
  <title>@nosleep</title>
</head>

<body>
</body>

</html>

Answer №1

To eliminate the need for javascript, you can create an element that covers the entire screen. Here is an example:

body {
  background: hsl(0,0%,50%);
}
a#fill{
  position:fixed;
  top:0;
  left:0;
  height:100vh;
  width:100vw;
  color: color:hsl(0,0%,80%);
  text-align: center;
  padding-top: 45vh;
  transition: .3s background-color, .3s color;
}
a#fill:hover {
  background-color: hsla(0,0%,0%,.3);
  color: white;
}
<a href="https://jsfiddle.net/" id="fill">click to visit jsfiddle</a>

If you prefer, you can achieve the same effect with plain javascript like this:

document.addEventListener("DOMContentLoaded", function() {
  document.getElementsByTagName('body')[0].addEventListener('click',function(){
     window.location = 'http://developer.mozilla.org';
  });
});

However, y

Answer №2

If you're looking for a way to incorporate a click event, check out this code snippet:

<script>
    $(document).ready(function () {
        $("body").on("click", function () { window.open('http://www.w3schools.com', '_blank'); });
    });
</script>

Feel free to use and modify as needed.

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

What is the best way to conceal text that overflows from a div and seamlessly return to the beginning once the end of the text has been reached?

I am struggling to figure out how to hide the overflow text that is spilling out of the div. I attempted using overflow: hidden;, but unfortunately, it didn't work as expected. Additionally, I would like the text to loop back to the beginning once it ...

Create a dynamic and interactive website using a combination of jQuery and AngularJS

I recently came across an interesting tidbit on the FAQs of Angular stating that "Angular can use jQuery if it's present in your app when the application is being bootstrapped". This got me thinking, is it considered a best practice to include both j ...

tips for integrating html5 elements with django forms

I am interested in utilizing the following code: # extra.py in yourproject/app/ from django.db.models import FileField from django.forms import forms from django.template.defaultfilters import filesizeformat from django.utils.translation import ugettext_ ...

Applying "Max-Height" property to the cells of a kendo

I've been struggling to figure out how to set a max-height for a tr or td element within a Kendo grid. Is it possible to set the height to 100% and restrict the max-height to 200px? The grid itself is scrollable with a height of 500px, so the scrollin ...

What is the best way to rearrange images within a grid container?

I apologize for asking numerous questions, but could someone please guide me on how to position an image slightly to the right of center or just 1 inch to the left of center? http://jsfiddle.net/96d7udd7/ Below is the HTML code snippet: <figure class ...

What is the best way to adjust the dimensions of a textfield in Vuetify by altering its width and height?

Is there a way to adjust both the width and height of the <v-text-field>tag? I attempted to modify it using .css, but it seems to only affect certain parameters, leaving large white spaces on my page. This is the method I have tried so far: <te ...

Tips on expanding a list within a div after the content in the list is complete

I find it frustrating to always manually enter fixed widths for divs depending on the number of letters in a li tag. <div> <ul> <li><a href="#">Home</a></li> <li><a href="#">Information</a>&l ...

Splitting up website content dynamically across various pages

I am interested in developing a webpage that showcases different versions of my code in a tabular format, arranged in reverse chronological order. An example of how I want it to look is provided below. Number Release Date End Date Requires ...

Tips for incorporating IntersectionObserver into an Angular mat-table to enable lazy loading功能?

I am looking to implement lazy loading of more data as the user scrolls down the table using IntersectionObserver. The container I am using is based on the Bootstrap grid system. However, despite using the code below, the callback function is not being tri ...

Is there a way to seamlessly transition the visibility of the Bootstrap 5.3 Spinner as it loads and unloads?

After delving into some research regarding Bootstrap-compatible spinners, I stumbled upon a piece of code. Take a look: function getData() { var spinner = document.getElementById("spinner"); spinner.style.display ...

Tips for implementing CSS on nested classes

<main> <div class="first-scheme"> <div class = "row"> <div class="col-sm-12"> <p>Hello World</p> ...

Navigate to a fresh webpage and find the scrollbar sitting at the bottom

When launching a new website using my forum system, I want the scrollbar to automatically be at the bottom so users don't have to scroll down. I'm not experienced in JavaScript and need help creating the code for this feature. ...

Utilize HTML to resize image to fit within container

I've encountered an issue while working with Adobe Dreamweaver CS5. I added a swap behavior to an image in an html document, expecting it to pop up at its original size and restore on mouse out. However, the swapped image ends up filling the entire sc ...

While I have the ability to include an overlay, I unfortunately lack the capability to delete it using jQuery

This feature will create an overlay on the entire browser screen using the defined properties. $('a.cell').click(function() { $('<div id = "overlay" />').appendTo('body').fadeIn("slow"); }); #overlay { backgroun ...

Problems arising from the checkbox in the table header being selected

I'm dealing with a table that features a 'Select All' checkbox as the first column in the header row. The issue I'm facing is that column headers usually serve to represent the data type of their respective columns. However, in this ca ...

Is it possible to connect a JavaScript file to an HTML document within a React application?

I have been developing a React website with the following file structure: public: index.html second.html src: index.js second.js table.js forms.js The main page (index.js) contains both a form and a table. One of the columns in the table has a link t ...

Staging a div from a specific origin

On my HTML page, there is one div and a small round image. Initially, the div has a scale of 0 so it is not displayed. However, when I click on the small image, the div scales to 1 in the middle of the window. The position of my div is absolute. My issue n ...

Make the width of the div equal to the width of its grandparent element

<div class = "box" style="width:100%;"> <div class = "left-side" style="width:50%;float:left;"> <div class = "inner-box" style="width:100%;"> </div> </div> <div class = "right-side" style="width: ...

Arranging the placement of list-group-item buttons

Looking for a way to create a list-group-item with two buttons that are equal in height and aligned to the right? Take a look at this example below: https://i.sstatic.net/II2nl.png While I have the basic structure in place, I'm having trouble gettin ...

The link button appears unselected without a border displayed

I am facing an issue with a link button in my code. Here is the snippet: <div class="col-2"> <a type="button" routerLink="auto-generate-schedules/generate" class="btn btn-primary mb-2">Generate Sche ...