Y
Y
Yurasic2020-09-13 12:14:27
URL Handling
Yurasic, 2020-09-13 12:14:27

How to make a condition based on the search result in the current URL?

Good day.
I am making a curved version of the site in two languages. And this option suits me in the constructor.
But in one place of the constructor, the built-in function doesn't work. I know it's not difficult to do this in JS, but I don't know how.
The question is very urgent .... Today, to hand over the site, but one page does not lend itself.

The principle is this

There is a site "URL"
We are looking for "?lang_ee" at the end of the URL.
If it is, write the text АААААААААААА
If it is not present, write the text BBBBBBBBBBBBBBB

Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twoone, 2020-09-13
@twoone

let params = new URLSearchParams(location.search);

if(params.has(`lang__ee`)){
    document.querySelector(`selector`).textContent = `Some Text`.
}else{
    document.querySelector(`selector`).textContent = `Other Text`.
}

selectorreplace with a valid selector of an existing element in which you want to output a message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question