0

I have this javascript code that is supposed to be refreshing a given web page after a specific amount of time and tries to find a certain word after each refresh. And when that word is found, a certain alarming sound is supposed to go off. here's the code:

javascript: var myRegExp = prompt("the word"); timeout = prompt("the time in seconds"); current = location.href; setTimeout('reload()', 1000 * timeout); var audio = new Audio('http://soundbible.com/grab.php?id=2197&type=mp3'); function reload() { var found = searchText(); if (!found) { setTimeout('reload()', 1000 * timeout); fr4me = '<frameset cols=\'*\'>\n<frame id="frame01" src=\'' + current + '\'/>'; fr4me += '</frameset>'; with(document) { write(fr4me); void(close()) }; } } function searchText() { var f = document.getElementById("frame01"); if (f != null && f.contentDocument != null) { var t = f.contentDocument.body.innerHTML; var matchPos = t.search(myRegExp); if (matchPos != -1) { audio.play(); return true; } else { return false; } } }

My question/request is, how to make the search for the word case insensitive?

5
  • Just lowercase the search text. And then perform the match. f.contentDocument.body.innerHTML.toLowerCase() Commented Feb 25, 2019 at 21:45
  • Possible duplicate of Refresh, find and alert using javascript Commented Feb 25, 2019 at 21:47
  • Please, don't post duplicate questions. Commented Feb 25, 2019 at 21:47
  • @jo_va it's the same code, but the question is different Commented Feb 25, 2019 at 22:38
  • It is not, from the other question: and also, how to make the search for the word case insensitive? Commented Feb 25, 2019 at 22:39

2 Answers 2

2

Use the ignoreCase option From the MDN

The ignoreCase property indicates whether or not the "i" flag is used with the regular expression. ignoreCase is a read-only property of an individual regular expression instance.

var regex1 = new RegExp('foo'); var regex2 = new RegExp('foo', 'i'); console.log(regex1.test('Football')); // expected output: false console.log(regex2.ignoreCase); // expected output: true console.log(regex2.test('Football')); // expected output: true 
Sign up to request clarification or add additional context in comments.

Comments

0

var regExp = /the word/i

For more on regex : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.