Home Web Front-end JS Tutorial How to implement web page character positioning in javascript_javascript skills

How to implement web page character positioning in javascript_javascript skills

May 16, 2016 pm 03:50 PM
javascript position

The example in this article describes the method of javascript realizing web page character positioning. Share it with everyone for your reference. The details are as follows:

Here you enter the string to be queried, and after clicking the position, the program will automatically jump to the matching position

<html>
<form name="f1" action=""
onSubmit="if(this.t1.value!=null && this.t1.value!='')
findString(this.t1.value);return false">
<input type="text" name=t1 value="" size=20>
<input type="submit" name=b1 value="Find">
</form>
<p>
导读:11月2日,美国将举行中期选举,众议院国会议员将全部改选,参议院改选1/3,一些州也将进行州长选举。奥巴马能否令心怀不满的选民支持民主党,支撑民主党统治,尚不得而知
</p>
<script language="JavaScript">
<!--
var TRange=null
function findString (str) {
 if (parseInt(navigator.appVersion)<4) return;
 var strFound;
 if (window.find) {
 // CODE FOR BROWSERS THAT SUPPORT window.find
 strFound=self.find(str);
 if (strFound && self.getSelection && !self.getSelection().anchorNode) {
  strFound=self.find(str)
 }
 if (!strFound) {
  strFound=self.find(str,0,1)
  while (self.find(str,0,1)) continue
 }
 }
 else if (navigator.appName.indexOf("Microsoft")!=-1) {
 // EXPLORER-SPECIFIC CODE
 if (TRange!=null) {
  TRange.collapse(false)
  strFound=TRange.findText(str)
  if (strFound) TRange.select()
 }
 if (TRange==null || strFound==0) {
  TRange=self.document.body.createTextRange()
  strFound=TRange.findText(str)
  if (strFound) TRange.select()
 }
 }
 else if (navigator.appName=="Opera") {
 alert ("Opera browsers not supported, sorry...")
 return;
 }
 if (!strFound) alert ("String '"+str+"' not found!")
 return;
}
//-->
</script>
</html>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to locate Apple wireless earphones if they are lost_How to locate Apple wireless earphones How to locate Apple wireless earphones if they are lost_How to locate Apple wireless earphones Mar 23, 2024 am 08:21 AM

1. First, we open the [Search] App on the mobile phone and select the device in the list on the device interface. 2. Then, you can check the location and click on the route to navigate there.

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

How to locate the other party's mobile phone location on Amap - How to locate the other party's mobile phone location on Amap How to locate the other party's mobile phone location on Amap - How to locate the other party's mobile phone location on Amap Apr 01, 2024 pm 02:11 PM

1. Click to enter the Amap map software on your mobile phone. 2. Click My in the lower right corner. 3. Click to enter the family map. 4. Click Create My Family Map. 5. After the creation is successful, an invitation code will appear and can be shared with another mobile phone.

How to change the location information and how to modify the address How to change the location information and how to modify the address Mar 12, 2024 pm 09:52 PM

We all know very clearly that Taku APP is a very reliable chat and social platform. Now it allows everyone to make friends online. Some of the forms of making friends here mainly allow people to make friends by location. Oh, it's so simple and direct. After all, it can automatically locate your current location information for you, and better match you with some friends in the same city who are close to each other, so that everyone can chat more easily and feel special. Happy, many times, in order to get to know more friends in other places, everyone has the idea of ​​​​modifying their address, but they don’t know how to modify their location information, which is very difficult. troubled, so the editor of this site also collected some specific

How to quickly find the location of a Huawei phone after it is lost? How to quickly find the location of a Huawei phone after it is lost? Mar 24, 2024 am 08:48 AM

In today's society, mobile phones have become an indispensable part of our lives. As a well-known smartphone brand, Huawei mobile phones are deeply loved by users. However, with the popularity of mobile phones and the increase in frequency of use, mobile phones are often lost. Once our phone is lost, we tend to feel anxious and confused. So, if you unfortunately lose your Huawei phone, how can you quickly find its location? Step 1: Use the mobile phone positioning function. Huawei mobile phones have built-in powerful positioning functions. Users can use the &quot;Security&quot; option in the mobile phone settings.

iPhone typing 'Oil found' triggers location? Can privacy still be guaranteed? iPhone typing 'Oil found' triggers location? Can privacy still be guaranteed? Apr 26, 2024 pm 01:28 PM

Recently, many users on the Internet said that when using Apple phones to search or comment on topics related to "discovering oil," the device will automatically turn on positioning. It is suspected that Apple phones are collecting and sending location information to monitor users. Will typing "Oil found" on iPhone trigger location? Can Apple's privacy be guaranteed in this way? Obviously, this is a misunderstanding! Apple customer service said that the positioning function is turned on by default, and any operation may trigger status updates, rather than being limited to sending specific text. But this statement is not entirely comprehensive. Generally, the iPhone rarely triggers the positioning function, unless you are searching for something, or the APP mechanism setting is related. When the user enters certain characters, the APP will automatically enable the positioning function in the background. Why can this topic

See all articles