Java – the SWT browser focuses on the next and previous highlighted text
I am developing a small application with SWT browser widget I'm emphasizing a search text
<a id="xyz" href=''><mark>test</mark></a>
In HTML documents And replace all search terms in HTML text in this way so that we can get all search terms highlighted
htmltext.replaceAll("(?i)"+Pattern.quote(searchword),"\\<a id='xyz' href=''> <mark>$0\\</mark></a>
I want to realize the function. If I click the next button, the next highlighted word should get the focus. If I click the previous button, the last highlighted text should get the focus How to use JavaScript in eclipse RCP application to complete next and previous hit
Solution
This is best solved by combining JavaScript with java code It depends on what kind of HTML content you want to handle, if it has state (for example, it can't be reloaded), a lot of dynamic JS code or pure static In most cases, the best solution will involve writing most of the logic into JS, while the smallest code in Java binds JS operations to SWT GUI
There are several things you need to do:
>Keyword search > toggle highlighting > switch from one word to another
1. Search: you realize that you will not be able to search for words that span multiple HTML elements, such as w < span > o < / span > Rd? If it doesn't matter, you can search and replace from Java as now I'll mark the matching ID of each character separately: < span id = "match1" > and remember how many games I found in total
You can also do this search on the JS side, or by adding a function that iterates through the DOM and searches for specific text and wraps it with another DOM object
2. Switch highlighting: it's best to complete it in JavaScript Attach a JS code snippet to your HTML and switch the DOM element style It's like:`
function highlight(id) { document.getElementById(id).className = 'highlighted' }
You can call swtbrowser Execute ("highlight ('match1 ')") calls this JS from SWT In addition, you should implement the highlighted function
翻译错误 TIMEOUT