Categories
JavaScript Answers

How to reload parent window from child window with JavaScript?

Sometimes, we want to reload parent window from child window with JavaScript.

In this article, we’ll look at how to reload parent window from child window with JavaScript.

How to reload parent window from child window with JavaScript?

To reload parent window from child window with JavaScript, we call window.opener.location.reload.

For instance, we write

window.opener.location.reload(false);

to reload parent window from the child window.

Conclusion

To reload parent window from child window with JavaScript, we call window.opener.location.reload.

Categories
JavaScript Answers

How to unfocus a textbox with JavaScript?

Sometimes, we want to unfocus a textbox with JavaScript.

In this article, we’ll look at how to unfocus a textbox with JavaScript.

How to unfocus a textbox with JavaScript?

To unfocus a textbox with JavaScript, we call the blur method.

For instance, we write

document.activeElement.blur();

to get the currently focused element with document.activeElement.

Then we call blur to unfocus the element.

Conclusion

To unfocus a textbox with JavaScript, we call the blur method.

Categories
JavaScript Answers

How to return string between square brackets with JavaScript?

Sometimes, we want to return string between square brackets with JavaScript.

In this article, we’ll look at how to return string between square brackets with JavaScript.

How to return string between square brackets with JavaScript?

To return string between square brackets with JavaScript, we use the string match method.

For instance, we write

const matches = myString.match(/\[(.*?)\]/);

if (matches) {
  const [, subMatch] = matches;
}

to call myString.match with a regex that matches the string between brackets.

(.*?) inside the brackets matches the group within the brackets.

Then we get the match from subMatch in the 2nd entry of the matches array.

Conclusion

To return string between square brackets with JavaScript, we use the string match method.

Categories
JavaScript Answers

How to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript?

Sometimes, we want to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript.

In this article, we’ll look at how to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript.

How to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript?

To convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript, we call the decodeURIComponent function.

For instance, we write

const fixedString = decodeURIComponent(escape(utfString));

to call escape to return an escaped version of the utfString string.

Then we call decodeURIComponent with the escaped string to convert it to the iso-8859-1 string.

Conclusion

To convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript, we call the decodeURIComponent function.

Categories
JavaScript Answers

How to fix .toLowerCase not working with JavaScript?

Sometimes, we want to fix .toLowerCase not working with JavaScript.

In this article, we’ll look at how to fix .toLowerCase not working with JavaScript.

How to fix .toLowerCase not working with JavaScript?

To fix .toLowerCase not working with JavaScript, we should convert the value to a string before calling toLowerCase.

For instance, we write

const ans = 334;
const temp = ans.toString().toLowerCase();
alert(temp);

to call ans.toString to convert it to a string.

And then we call toLowerCase to return the string in lower case.

Conclusion

To fix .toLowerCase not working with JavaScript, we should convert the value to a string before calling toLowerCase.