Special symbols used in a URL - searching for the uppercase Ø

Here is the URL I am working with:

my.website/?param1=Økonomi&param2=Penger

In order to retrieve the parameter values, I am using the following function:

function extractParamValue(url, key) {
    var parameters = {};
    var urlParams = url.split("?", 2);

    if (urlParams.length > 1) {
        var paramList = urlParams[1].split("&");
        paramList.map(function (paramString) {
            var keyValue = paramString.split("=", 2);
            parameters[keyValue[0]] = keyValue[1];
        });
    }
    return (key in parameters)? decodeURIComponent(parameters[key]) : ''
}

When I check the results after extracting, I see that the values returned are: param1 = %C3%98konomi and param2 = Penger

However, when I compare these values with my dataset, I am unable to find a match for Økonomi where Ø has a capital letter. Interestingly, if I change it to økonomi, then I do get a match.

Why is it that the encoded URI value %C3%98 is not translating to Ø? How can I ensure that it does in future queries?

Answer №1

Follow these steps:

const getQueryStringValue = (url, key) => 
    ((decodeURIComponent(url).split('?')[1] || '').match(new RegExp(`${key}=([^&]*)`)) || [,null])[1]

const url = encodeURIComponent('my.site/?param1=Økonomi&param2=Penger')
console.log(getQueryStringValue(url, 'param1'))
console.log(getQueryStringValue(url, 'param2'))
console.log(getQueryStringValue('my.site/', 'param2'))
console.log(getQueryStringValue('my.site/?param1=Økonomi&param2=Penger', 'param3'))

Browsers encode URLs using the encodeUriComponent function and you must decode them.

console.log(decodeURIComponent('%C3%98'))

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

Tips for effectively passing state from a parent component to a child component without losing it

I created a view displaying all posts with a filter above them. Users can customize their view by selecting different options on the filter, resulting in updated posts being shown. However, if a user clicks on a post after applying filters, the parent com ...

How to retrieve the value instead of the key/ID in a Laravel controller?

I am extracting data from the database and displaying it on the invoice view page using the json_encode($items); function. When I try to insert the 'price' field into the database, only the id/key is being stored instead of the actual value. Any ...

retrieving the value of an AngularJS variable based on which radio button

I've experimented with various versions of code, but I haven't been able to find a solution yet. Here's the code snippet: <div class="well"> <h3>{{policies.aul.name}}</h3> <ul style="list-style: none;"> ...

Steps to retrieve the content of a div element and store it in a variable in Ionic 4

I am currently using Ionic 4 and need to extract the text from within my div. Below is the code snippet from home.page.html: <ion-item> <div id="Target" class="editable" [innerHtml]="resume" contenteditable> <p>Lorem ipsum d ...

What could be the reason for incorrect data being sent when using multi-select values with jQuery/A

I implemented a multi-select dropdown menu where users can select values. Whenever a user selects a value, a jQuery/AJAX request is sent to the server. Check out the code snippet below: $("#send").on("click", function() { var elem$ = $("#cars"), el ...

Learn how to create text animations using CSS triggered by a scroll event listener

I'm looking to create a text animation similar to the one on this website: They have 3 keyframes for two types of animations: Left to Right and Right to Left. The RTL animation starts at 164vh, while LTR starts at -200vh. These text animations only ...

Insert a new row with a designated row class

I have a table with 2 columns and an "add row" button. However, I want to add a new row between the rows with the classes "title" and "ongkir". Currently, the new row is being added after the "ongkir" row. Can someone please assist me in achieving this? B ...

What is the best way to generate a one-level breadcrumb using Jquery?

In certain applications, I am interested in implementing a single-level breadcrumb trail that looks like this: Home -> Product -> Applications -> Application 1 Since 'Applications' can have several children, I want to incorporate a dro ...

How to send configuration data to an external library in Angular 6 in the app.module.ts file

My goal is to provide basic configuration settings to an external or third-party module. These settings are stored in a JSON file for easy modification across different environments without the need to rebuild the code. import { BrowserModule } from &apos ...

The object filtering process is experiencing issues due to the presence of a null value in the column

I am trying to extract object data based on a specific value from an array. While the code snippet below works well when there are no null values, it fails to work properly when encountering null values in the column. For reference, you can check out this ...

Creating an HTML5 input pattern specifically for validating Irish Vat Numbers

The required format for an Irish VAT number is as follows: It should consist of either seven digits followed by one letter or six digits followed by two letters. What would be the appropriate HTML5 input pattern for validating this format? I have attempt ...

I'm confused as to why this is occurring even though the codes appear to be identical

this.state = { lat: null }; window.navigator.geolocation.getCurrentPosition( pos=>{ this.setState({lat:pos.coords.latitude}); }, err=>{ console.log(err); } ); There seems to be an issue where using setState inside a ...

Why is it possible for the EXPRESS+EJS template to access CONFIG without explicitly passing it when rendering?

Currently exploring my knowledge of node.js alongside express and the ejs template. As I delved into some code, I stumbled upon the fact that they were able to invoke config in the template without explicitly passing it as a variable during rendering. You ...

Trouble with an external .js script

function displayMessage() { var isConfirmed = confirm("Do you want to proceed?"); if (isConfirmed) { window.location = "./proceed"; } }; function checkIfEmpty(){ console.log("checkIfEmpty"); }; @CHARSET "ISO-8859-1"; form { margin:0 auto; width:300px ...

Instructions for uploading STL files in HTML with three.js

My current project involves creating a web application that allows users to upload and view STL files generated by MATLAB code. However, I'm encountering difficulties when it comes to passing parameters in the STL load function. As I searched for sol ...

Unable to implement a filter on data retrieved through $http in Angular framework

I have a situation where I am retrieving data from an API in my controller using $http.get, and then I want to enhance the appearance of this data by applying a text formatting filter. However, I keep encountering TypeError: Cannot read property 'sp ...

I am looking to integrate a custom button that, when clicked, will launch the file explorer for me to choose a file. Once selected, the file name should automatically populate in the input field

In the code below, when the button is clicked, Windows Explorer should open and allow the user to select a file. The selected file should then be displayed in the input field. The file type should not be 'File'. <Grid.Column width={8}> ...

Enhance your Verold model object with engaging animations

Trying to utilize verold for animating 3D models through a script has been challenging. The proper usage of the verold API components seems unclear at the moment. A model has been successfully loaded into the scene with a script attached as an attribute o ...

What is the best way to implement rate limiting for asynchronous API calls within a specific timeframe?

I have a project that requires me to make over 500 calls simultaneously from my NodeJS server to a third-party server. The issue is that the third-party server has a restriction of only allowing a maximum of 50 calls per second. Can someone assist me in im ...

Be patient for the complete loading of the image during an AJAX operation

My webpage includes an ajax action that loads a div containing an image on the left and text on the right. The issue I am facing is that the text loads first, aligned to the left, and then the image loads, causing the text to shift to the right, resulting ...