Unable to load page redirection

I am experiencing an issue with this page not redirecting to the appropriate mobile or desktop page when accessed. Below is the code snippet in question:

<html>
    <head>
        <title>Loading...</title>
    </head>
    <script>
        window.onload = function() {
        var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
        if (iOS == true) {
        window.location.href="http://m.lifewithzooza.x10host.com/";
        } else {
        window.location.href="http://lifewithzooza.x10host.com/wordpress/";
        }
    </script>
    <body bgcolor="#FFFFFF">
        Loading...
    </body>
</html>

This is my first time seeking assistance on Stack Overflow, so I may not be familiar with all the necessary details. Thank you for your help.

Answer №1

You need to add the closing } for the onload function in your code. Make sure to update your code as shown below:

window.onload = function() {
        var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
        if (iOS == true) {
        window.location.href="http://m.lifewithzooza.x10host.com/";
        } else {
        window.location.href="http://lifewithzooza.x10host.com/wordpress/";
        }
}

Answer №2

You are missing a closing bracket }, which is why it's not working. You forgot to include the closing bracket } for the

window.onload = function() { //your code goes here }

Please make sure to review the code that is being executed

 window.onload = function() {
        var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
        if (iOS == true) {
        window.location.href="http://m.lifewithzooza.x10host.com/";
        } else {
        window.location.href="http://lifewithzooza.x10host.com/wordpress/";
        }
   }
<html>
    <head>
        <title>Loading...</title>
    </head>
   
    <body bgcolor="#FFFFFF">
        Loading...
    </body>
</html>

Answer №3

There are 2 issues that need to be addressed:

  • Your script element is placed in an incorrect location. According to W3 guidelines, the script tag should be placed within either the body or head section of the HTML document, and not randomly in between. The correct placement is important for proper functionality.
  • Another error is that you have missed a } in your onload function.

<html>
    <head>
        <title>Loading...</title>
        <script>
        window.onload = function() {
            var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
            if (iOS) {
                window.location.href="http://m.lifewithzooza.x10host.com/";
            } else {
                window.location.href="http://lifewithzooza.x10host.com/wordpress/";
            }
        }
    </script>
    </head>
    <body bgcolor="#FFFFFF">
        Loading...
    </body>
</html>

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

Issue with Angular 2 pipe causing unexpected undefined result

Here is a JSON format that I am working with: [{ "id": 9156, "slug": "chicken-seekh-wrap", "type": "dish", "title": "Chicken Seekh Wrap", "cuisine_type": [2140] }, { "id": 9150, "slug": "green-salad", "type": "dish", "title": "Green Sala ...

jQuery returns varying values for checked status when using click() method versus manual click

I'm facing an issue with a checkbox generating dynamic content. Whenever I try to pre-create the dynamic content on page load by using click(), the "checked" attribute is not set until after the click function finishes. Strangely, when I manually cli ...

What is the reason for the viewport in three.js renderer not functioning properly on IE browser?

Try setting the viewport with different coordinates: this.renderer.setViewport(50, -50, this.width, this.height); What could be causing issues with IE browser compatibility? ...

Encountering a 403 error while attempting to retrieve an image

I'm currently facing difficulties in displaying firebase storage images on my Next.js application due to persistent 403 errors. When I add a document to Firestore, I upload an image to storage with a nested URL and use that URL to retrieve the image. ...

Delete the entry with the specified unique identifier "this text" from the MongoDB database

So, I've been searching high and low but still can't seem to figure out how to get this to work. Here's the issue I'm facing: I'm currently working on a chat application using node/express/socketio, and I'm attempting to crea ...

Experiencing trouble with calculating the total value of an array of objects due to NaN errors

I've been working on developing this web application in VUE.js, but I'm facing an issue with a specific function where I am attempting to sum the values of each object within an array. This is resulting in a NaN (Not a Number) error. Let's t ...

Node.js and Express: ensuring completion of asynchronous operation before responding to HTTP request

Imagine there is a callback function set up for an HTTP GET request, structured like this: router.get('/latestpost', function(req, res, next) { var data = new FbData(); get_latest_post (data); get_post_image (data); res.json(da ...

Update the link to a KML file used by Google Maps when a button is clicked

On the initial page load, I want to showcase an 8 Day Average KML file on Google Maps. However, users should have the option to click on the "1 Day" and "3 Day" buttons to switch the reference in Google Maps from the "8 Day" file. The aim is to design a s ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

Checking the Signature with Elrond in the Backend using PHP

My latest decentralized application allows users to log in using their Elrond wallet and generate a unique signature containing their wallet address and additional data. As part of the authorization process, the signature is included in the payload of req ...

Exploring the best way to use $set in Mongoose for dynamically updating an embedded

I'm currently attempting to create a unique function that can update the value of a specific embedded MongoDB document within an array. The goal is to change the value based on its position. function removeAddress(accountNum, pos) { const remove ...

Argument not accepted in JavaScript

Currently, I am encountering a unique error message while working with a complex function that iterates through elements in my JavaScript onSuccess event. The error I am seeing is: exception encountered : {"message": "Invalid argument.", "description": " ...

JQuery is having issues with $(this) and the find function not working properly

I am attempting to access a child of the div with the class form-group, specifically, I want to display the value of the input element. <div class="form-group"> <label>text</label> <input name="text" type="text" class="form-co ...

A guide on incorporating a method using ES6 Rest into a JavaScript object

My goal is to enhance my Person constructor by adding a method that allows users to add friends. I wanted to utilize the "rest" feature of ES6 to pass a variable number of friends, but I seem to be stuck. My initial attempt resulted in an error ("Uncaught ...

JavaScript - splitting numbers into multiple parts

Need help with a JavaScript question regarding numbers like 2,5 or 2.5 I attempted to perform a multi-split operation using the following code: '2.5'.split(/,|./) However, it resulted in an incorrect output: ["", "", "", ""] ...

Javascript will not recognize or interpret PHP's HTML tags

When PHP sends HTML strings to HTML through AJAX wrapped in <p class="select"></p> tags, the CSS reads the class perfectly. However, JavaScript/jQuery does not seem to work as expected. Even when trying to parse <p onclick="function()">&l ...

Calculate the number of parent nodes and their respective child nodes

I am curious about how I can determine the number of children nested within parent-child relationships. For example: const parent = document.querySelectorAll('.parent'); parent.forEach(el => { const ul = el.querySelector('.child3-chi ...

What is the best way to add 1 to a number every second with javascript?

My code seems to be functioning correctly, but I'm having trouble setting the delay and stopping the increment after a certain interval. Can someone please assist me with this? Javascript: $(document).ready(function() { var number = parseInt($(& ...

What method can I use in Javascript to extract the mealtype data from the Edamam nutritional API?

My goal is to extract the mealtype information from the API linked below. After reviewing the API, it seems that a POST request is required to retrieve mealType data. However, I am uncertain about the correct syntax for this request. For instance, if a u ...

Activate SVG graphics upon entering the window (scroll)

Can anyone assist me with a challenging issue? I have numerous SVG graphics on certain pages of my website that start playing when the page loads. However, since many of them are located below the fold, I would like them to only begin playing (and play onc ...