CN110083352A - JS code injection method, apparatus, computer equipment and storage medium - Google Patents

JS code injection method, apparatus, computer equipment and storage medium Download PDF

Info

Publication number
CN110083352A
CN110083352A CN201910214279.6A CN201910214279A CN110083352A CN 110083352 A CN110083352 A CN 110083352A CN 201910214279 A CN201910214279 A CN 201910214279A CN 110083352 A CN110083352 A CN 110083352A
Authority
CN
China
Prior art keywords
file
injection
script
text
injected
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910214279.6A
Other languages
Chinese (zh)
Inventor
陈翔
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN201910214279.6A priority Critical patent/CN110083352A/en
Publication of CN110083352A publication Critical patent/CN110083352A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/38Creation or generation of source code for implementing user interfaces

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses JS code injection method, apparatus, computer equipment and storage mediums.This method comprises: receiving the JS injection file that third party's terminal is uploaded, JS injection file is sent to corresponding expansion interface;Judge the file type of the JS injection file;If the file type of the JS injection file is the address URL, the address URL is spliced by link script by the expansion interface, the link script is injected into browser page;And if the file type of JS injection file is JS text, and escape character illegal in the JS text is replaced to obtain JS script by the expansion interface, the JS script is injected into the browser page.This method realizes the JS code for providing and managing oneself by third party using data transfer optimization technology by providing third party JS injectability interface, without providing adaptation for third-party demand, is conducive to later maintenance.

Description

JS code injection method, apparatus, computer equipment and storage medium
Technical field
The present invention relates to data transfer optimization field more particularly to a kind of JS code injection method, apparatus, computer equipment And storage medium.
Background technique
Currently, application program generally can all quote many third-party SDK, (full name is Software Development Kit indicates Software Development Kit), and the Webview (network view) that third party SDK is often made with host is shown The page, these pages generally require that (full name is javascript, it is a kind of literal translation formula scripting language, is a kind of dynamic by js State type, weak type, the language based on prototype, built-in support type) realize that Webview webpage and SDK interact.If answered Specific processing adaptation is done to for third-party page business demand with the exploitation operator of program, then third party's SDK industry Business just needs and application program coupling, and the workload of coupling is huge, is unfavorable for later maintenance.
Summary of the invention
The embodiment of the invention provides a kind of JS code injection method, apparatus, computer equipment and storage mediums, it is intended to solve Specific processing adaptation certainly is done for third-party page business demand in the prior art, third party SDK business just needs and this is answered It is coupled with program, the workload of coupling is huge, the problem of being unfavorable for later maintenance.
In a first aspect, the embodiment of the invention provides a kind of JS code injection methods comprising:
The JS injection file that third party's terminal is uploaded is received, JS injection file is sent to corresponding extension and is connect Mouthful;
Judge the file type of the JS injection file;
If the file type of the JS injection file is the address URL, the address URL is spliced by the expansion interface To link script, the link script is injected into browser page;And
It, will be illegal in the JS text by the expansion interface if the file type of the JS injection file is JS text Escape character is replaced to obtain JS script, and the JS script is injected into the browser page.
Second aspect, the embodiment of the invention provides a kind of JS code injection devices comprising:
File obtaining unit is injected, file is injected for receiving the JS that third party's terminal is uploaded, the JS is injected into text Part is sent to corresponding expansion interface;
File type judging unit, for judging the file type of the JS injection file;
First injection unit passes through the expansion interface if the file type for JS injection file is the address URL The address URL is spliced into link script, the link script is injected into browser page;And
Second injection unit passes through the expansion interface if the file type for JS injection file is JS text Escape character illegal in the JS text is replaced to obtain JS script, the JS script is injected into the browser page Face.
The third aspect, the embodiment of the present invention provide a kind of computer equipment again comprising memory, processor and storage On the memory and the computer program that can run on the processor, the processor execute the computer program JS code injection method described in the above-mentioned first aspect of Shi Shixian.
Fourth aspect, the embodiment of the invention also provides a kind of computer readable storage mediums, wherein the computer can It reads storage medium and is stored with computer program, it is above-mentioned that the computer program when being executed by a processor executes the processor JS code injection method described in first aspect.
The embodiment of the invention provides a kind of JS code injection method, apparatus, computer equipment and storage mediums.This method File is injected including receiving the JS that third party's terminal is uploaded, JS injection file is sent to corresponding expansion interface;Sentence The JS that breaks injects the file type of file;If the file type of the JS injection file is the address URL, connect by the extension The address URL is spliced into link script by mouth, and the link script is injected into browser page;And if JS injection The file type of file is JS text, and escape character illegal in the JS text is replaced to obtain by the expansion interface To JS script, the JS script is injected into the browser page.This method, which passes through, provides third party JS injectability interface, The JS code for providing and managing oneself by third party is realized, without providing adaptation for third-party demand, is tieed up conducive to the later period Shield.
Detailed description of the invention
Technical solution in order to illustrate the embodiments of the present invention more clearly, below will be to needed in embodiment description Attached drawing is briefly described, it should be apparent that, drawings in the following description are some embodiments of the invention, general for this field For logical technical staff, without creative efforts, it is also possible to obtain other drawings based on these drawings.
Fig. 1 is the application scenarios schematic diagram of JS code injection method provided in an embodiment of the present invention;
Fig. 2 is the flow diagram of JS code injection method provided in an embodiment of the present invention;
Fig. 3 is another flow diagram of JS code injection method provided in an embodiment of the present invention;
Fig. 4 is the sub-process schematic diagram of JS code injection method provided in an embodiment of the present invention;
Fig. 5 is another sub-process schematic diagram of JS code injection method provided in an embodiment of the present invention;
Fig. 6 is another sub-process schematic diagram of JS code injection method provided in an embodiment of the present invention;
Fig. 7 is the schematic block diagram of JS code injection device provided in an embodiment of the present invention;
Fig. 8 is another schematic block diagram of JS code injection device provided in an embodiment of the present invention;
Fig. 9 is the subelement schematic block diagram of JS code injection device provided in an embodiment of the present invention;
Figure 10 is another subelement schematic block diagram of JS code injection device provided in an embodiment of the present invention;
Figure 11 is another subelement schematic block diagram of JS code injection device provided in an embodiment of the present invention;
Figure 12 is the schematic block diagram of computer equipment provided in an embodiment of the present invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete Site preparation description, it is clear that described embodiments are some of the embodiments of the present invention, instead of all the embodiments.Based on this hair Embodiment in bright, every other implementation obtained by those of ordinary skill in the art without making creative efforts Example, shall fall within the protection scope of the present invention.
It should be appreciated that ought use in this specification and in the appended claims, term " includes " and "comprising" instruction Described feature, entirety, step, operation, the presence of element and/or component, but one or more of the other feature, whole is not precluded Body, step, operation, the presence or addition of element, component and/or its set.
It is also understood that mesh of the term used in this description of the invention merely for the sake of description specific embodiment And be not intended to limit the present invention.As description of the invention and it is used in the attached claims, unless on Other situations are hereafter clearly indicated, otherwise " one " of singular, "one" and "the" are intended to include plural form.
It will be further appreciated that the term "and/or" used in description of the invention and the appended claims is Refer to any combination and all possible combinations of one or more of associated item listed, and including these combinations.
Fig. 1 and Fig. 2 are please referred to, Fig. 1 is the application scenarios schematic diagram of JS code injection method provided in an embodiment of the present invention, Fig. 2 is the flow diagram of JS code injection method provided in an embodiment of the present invention, which is applied to terminal In, which can be the electronic equipments such as mobile phone, tablet computer, laptop computer, desktop computer.It is equipped in the terminal using journey Sequence, wherein the application program can be native applications program, web application or mixed application.This method passes through installation Application software in terminal is executed.
As shown in Fig. 2, the method comprising the steps of S110~S140.
S110, the JS injection file that third party's terminal is uploaded is received, JS injection file is sent to corresponding expansion Open up interface.
In the present embodiment, the APP application program of terminal local introduces many third-party Software Development Kit (i.e. SDK), and third party SDK is often made with the Webview (network view) of host App (i.e. the APP application program of terminal local) Show some pages, these pages, which generally require to inject by JS, realizes that Webview and third party SDK is interacted.
When the interface of the APP application program of terminal local is open to third party SDK, the JS note of third party SDK can receive Enter file, it is one section of JavaScript code of input in browser address bar that wherein JS, which injects file, for changing page JS The content of variable, page-tag.
(i.e. UIWebview, UIWebView class are to use to browser page in APP application program in order to make terminal local It shows Web content, can simply create a UIWebView object using it, be placed on window, and send one A request for being directed toward Web content.By this class, the forward-reverse of web-page histories can control, can also go to control by program The attribute of Web content processed) have the JS injection file that reception third party's terminal is uploaded, it needs through Category characteristic (Category refers to the extension to a class) extends an interface to UIWebview, is exclusively used in receiving and handling JS injection text Part.
In one embodiment, as shown in figure 3, before step S110 further include:
S101, browser page is connect by the Category characteristic of speech sounds for increasing method to already present class Mouth extension, be expanded interface.
In the present embodiment, Category is the characteristic of speech sounds of addition after Objective-C 2.0, the master of Category Act on such as is carried out the extension of interface to UIWebView class and connects to be expanded for already existing class adding method Mouthful.It is expanded interface by carrying out Interface Expanding to UIWebView class, to have the energy for receiving third party SDK injection Power, convenient for being interacted with third hair SDK.
S120, the file type for judging the JS injection file.
In the present embodiment, the file type is mainly the address URL and JS text;Wherein, in the address URL URL it is complete Title is Uniform Resource Locator, uniform resource locator is indicated, to the resource that can be obtained from internet The succinct expression of one kind of position and access method, is the address of standard resource on internet;JS full name is in JS text JavaScript is one kind of webpage development design language.Judge JS injection file to be to be the address URL or JS text, be for Targetedly JS injection file is further processed.
If the file type that S130, the JS inject file is the address URL, by the URL by the expansion interface Location is spliced into link script, and the link script is injected into browser page.
In the present embodiment, if the JS injection file file type be the address URL, only need to by the address URL with HTML document is spliced into link script, is then injected into browser page.If the injection of third party's terminal It is the address URL that JS, which injects file, is to obtain the address URL to correspond to the newest web page contents obtained in webpage and be injected into parsing Browser page, so that third party possesses the ability that Online release repairs JS code.
In one embodiment, as shown in figure 4, step S130 includes:
S131, the head for constructing HTML document, obtain initial treatment file;
S132, the address URL is injected into the main part after being located at head in the initial treatment file, obtains chain Pin sheet.
In the present embodiment, (full name of HTML is HyperText to HTML document, that is, html file Markup Language), head, that is, part head of html file, head label is used for the head of definition document, it is all The container of header elements.Element in<head>can quote script, where instruction browser finds style sheet, provide member letter Breath etc..The head of document describes each attribute and information of document, the title including document, the position in Web and With the relationship of other documents etc..
The part main part, that is, html file body, it includes all the elements of document, such as text, hyperlink, image, Table, list etc.;
It is before the head of html file<html>beginning, main part are later</html>ending, for complete as one The beginning and end of whole html file;
The address URL is received by carrier of HTML document, browser page is then injected into, meets The JS interaction demand of the APP application program of third party SDK and terminal local.
In one embodiment, as shown in figure 5, after step S132 further include:
S133, web page contents corresponding with the address URL are obtained according to the link script;
S134, the web page contents are injected into the browser page.
In the present embodiment, the address URL is injected into main part, indicates that JS injection content acquired in the link script is It is obtained by the corresponding address URL, if the content under the address URL updates, the link script is injected into institute herein It is that the what be new under the address URL is injected into the browser page, so that third party possesses online when stating browser page The ability of JS is repaired in publication.
By the above-mentioned means, the APP application program of terminal local provides the ability and terminal local of third party JS injection The local JS injection of APP application program distinguish, prevent the coupling of dangerous and business, ensure that the independence of injection, and And in JS injection process, do not have to provide adaptation for third-party demand.
If the file type of S140, the JS injection file is JS text, by the expansion interface by the JS text In illegal escape character be replaced to obtain JS script, the JS script is injected into the browser page.
In one embodiment, as shown in fig. 6, step S140 includes:
S141, the head for constructing HTML document, obtain initial treatment file;
S142, judge in the JS text whether to include preset illegal escape character;
If in S143, the JS text include at least one described illegal escape character, by the illegal escape character into Row shielding, JS text after being handled;
S144, JS text after the processing is injected into the main part after being located at head in initial treatment file, obtained The JS script;
If not including the illegal escape character in S145, the JS text, the JS text is injected into initial treatment The main part being located at after head in file, obtains the JS script.
The head for first constructing html file, obtains initial treatment file;Judge in the JS text whether to include default Illegal escape character;Wherein, preset illegal escape character include, ", ', n, r, f;If being wrapped in the JS text The illegal escape character is included, the illegal escape character is shielded, JS text after being handled, wherein screen Cover, ", ' be be in front plus, shielding n, r, f when be in front plus;The JS text is injected into just Begin to handle the main part being located at after head in file, obtains JS script.
JS text is shielded to JS text after being converted to processing after illegal escape character in the present embodiment and is injected into main body Portion indicates that JS injection content acquired in the JS script is directly to be obtained by the JS script, when third party SDK needs to update When JS injects content, newest JS text is injected by expansion interface again.
This method realizes the JS generation for providing and managing oneself by third party by providing third party JS injectability interface Code is conducive to later maintenance without providing adaptation for third-party demand.
The embodiment of the present invention also provides a kind of JS code injection device, and the JS code injection device is for executing aforementioned JS generation Any embodiment of code method for implanting.Specifically, referring to Fig. 7, Fig. 7 is JS code injection device provided in an embodiment of the present invention Schematic block diagram.The JS code injection device 100 can be configured in terminal.
As shown in fig. 7, JS code injection device 100 includes injection file obtaining unit 110, file type judging unit 120, the first injection unit 130, the second injection unit 140.
File obtaining unit 110 is injected, file is injected for receiving the JS that third party's terminal is uploaded, the JS is injected File is sent to corresponding expansion interface.
In the present embodiment, the APP application program of terminal local introduces many third-party Software Development Kit (i.e. SDK), and third party SDK is often made with the Webview (network view) of host App (i.e. the APP application program of terminal local) Show some pages, these pages, which generally require to inject by JS, realizes that Webview and third party SDK is interacted.
When the interface of the APP application program of terminal local is open to third party SDK, the JS note of third party SDK can receive Enter file, it is one section of JavaScript code of input in browser address bar that wherein JS, which injects file, for changing page JS The content of variable, page-tag.
(i.e. UIWebview, UIWebView class are to use to browser page in APP application program in order to make terminal local It shows Web content, can simply create a UIWebView object using it, be placed on window, and send one A request for being directed toward Web content.By this class, the forward-reverse of web-page histories can control, can also go to control by program The attribute of Web content processed) have the JS injection file that reception third party's terminal is uploaded, it needs through Category characteristic (Category refers to the extension to a class) extends an interface to UIWebview, is exclusively used in receiving and handling JS injection text Part.
In one embodiment, as shown in figure 8, JS code injection device 100 further include:
Expansion interface construction unit 101, for special by the Category language for increasing already present class method Property to browser page carry out Interface Expanding, be expanded interface.
In the present embodiment, Category is the characteristic of speech sounds of addition after Objective-C 2.0, the master of Category Act on such as is carried out the extension of interface to UIWebView class and connects to be expanded for already existing class adding method Mouthful.It is expanded interface by carrying out Interface Expanding to UIWebView class, to have the energy for receiving third party SDK injection Power, convenient for being interacted with third hair SDK.
File type judging unit 120, for judging the file type of the JS injection file.
In the present embodiment, the file type is mainly the address URL and JS text;Wherein, in the address URL URL it is complete Title is Uniform Resource Locator, uniform resource locator is indicated, to the resource that can be obtained from internet The succinct expression of one kind of position and access method, is the address of standard resource on internet;JS full name is in JS text JavaScript is one kind of webpage development design language.Judge JS injection file to be to be the address URL or JS text, be for Targetedly JS injection file is further processed.
First injection unit 130 passes through the extension if the file type for JS injection file is the address URL The address URL is spliced into link script by interface, and the link script is injected into browser page.
In the present embodiment, if the JS injection file file type be the address URL, only need to by the address URL with HTML document is spliced into link script, is then injected into browser page.If the injection of third party's terminal It is the address URL that JS, which injects file, is to obtain the address URL to correspond to the newest web page contents obtained in webpage and be injected into parsing Browser page, so that third party possesses the ability that Online release repairs JS code.
In one embodiment, as shown in figure 9, the first injection unit 130 includes:
First file construction unit 131 obtains initial treatment text for constructing the head of HTML document Part;
The address URL injection unit 132 is located at head for the address URL to be injected into the initial treatment file Main part later obtains link script.
In the present embodiment, (full name of HTML is HyperText to HTML document, that is, html file Markup Language), head, that is, part head of html file, head label is used for the head of definition document, it is all The container of header elements.Element in<head>can quote script, where instruction browser finds style sheet, provide member letter Breath etc..The head of document describes each attribute and information of document, the title including document, the position in Web and With the relationship of other documents etc..
The part main part, that is, html file body, it includes all the elements of document, such as text, hyperlink, image, Table, list etc.;
It is before the head of html file<html>beginning, main part are later</html>ending, for complete as one The beginning and end of whole html file;
The address URL is received by carrier of HTML document, browser page is then injected into, meets The JS interaction demand of the APP application program of third party SDK and terminal local.
In one embodiment, as shown in Figure 10, the first injection unit 130 further include:
Web page contents acquiring unit 133, for being obtained in webpage corresponding with the address URL according to the link script Hold;
Content injection unit 134, for the web page contents to be injected into the browser page.
In the present embodiment, the address URL is injected into main part, indicates that JS injection content acquired in the link script is It is obtained by the corresponding address URL, if the content under the address URL updates, the link script is injected into institute herein It is that the what be new under the address URL is injected into the browser page, so that third party possesses online when stating browser page The ability of JS is repaired in publication.
By the above-mentioned means, the APP application program of terminal local provides the ability and terminal local of third party JS injection The local JS injection of APP application program distinguish, prevent the coupling of dangerous and business, ensure that the independence of injection, and And in JS injection process, do not have to provide adaptation for third-party demand.
Second injection unit 140 is connect if the file type for JS injection file is JS text by the extension Escape character illegal in the JS text is replaced to obtain JS script by mouth, and the JS script is injected into the browser The page.
In one embodiment, as shown in figure 11, the second injection unit 140 includes:
Second file construction unit 141 obtains initial treatment text for constructing the head of HTML document Part;
Illegal escape character judging unit 142, for judging in the JS text whether to include preset illegal escape word Symbol;
Character shields conversion unit 143, if for including at least one described illegal escape character in the JS text, it will The illegal escape character is shielded, JS text after being handled;
First JS script acquiring unit 144 is located at for JS text after the processing to be injected into initial treatment file Main part after head obtains the JS script;
2nd JS script acquiring unit 145, if for not including the illegal escape character in the JS text, it will be described JS text is injected into the main part being located at after head in initial treatment file, obtains the JS script.
The head for first constructing html file, obtains initial treatment file;Judge in the JS text whether to include default Illegal escape character;Wherein, preset illegal escape character include, ", ', n, r, f;If being wrapped in the JS text The illegal escape character is included, the illegal escape character is shielded, JS text after being handled, wherein screen Cover, ", ' be be in front plus, shielding n, r, f when be in front plus;The JS text is injected into just Begin to handle the main part being located at after head in file, obtains JS script.
JS text is shielded to JS text after being converted to processing after illegal escape character in the present embodiment and is injected into main body Portion indicates that JS injection content acquired in the JS script is directly to be obtained by the JS script, when third party SDK needs to update When JS injects content, newest JS text is injected by expansion interface again.
The device realizes the JS generation for providing and managing oneself by third party by providing third party JS injectability interface Code is conducive to later maintenance without providing adaptation for third-party demand.
Above-mentioned JS code injection device can be implemented as the form of computer program, which can be in such as Figure 12 Shown in run in computer equipment.
Figure 12 is please referred to, Figure 12 is the schematic block diagram of computer equipment provided in an embodiment of the present invention.The computer is set Standby 500 be terminal, which can be the electronic equipments such as mobile phone, tablet computer, laptop computer, desktop computer.
Refering to fig. 12, which includes processor 502, memory and the net connected by system bus 501 Network interface 505, wherein memory may include non-volatile memory medium 503 and built-in storage 504.
The non-volatile memory medium 503 can storage program area 5031 and computer program 5032.The computer program 5032 are performed, and processor 502 may make to execute JS code injection method.
The processor 502 supports the operation of entire computer equipment 500 for providing calculating and control ability.
The built-in storage 504 provides environment for the operation of the computer program 5032 in non-volatile memory medium 503, should When computer program 5032 is executed by processor 502, processor 502 may make to execute JS code injection method.
The network interface 505 is for carrying out network communication, such as the transmission of offer data information.Those skilled in the art can To understand, structure shown in Figure 12, only the block diagram of part-structure relevant to the present invention program, is not constituted to this hair The restriction for the computer equipment 500 that bright scheme is applied thereon, specific computer equipment 500 may include than as shown in the figure More or fewer components perhaps combine certain components or with different component layouts.
Wherein, the processor 502 is for running computer program 5032 stored in memory, to realize following function Can: the JS injection file that third party's terminal is uploaded is received, JS injection file is sent to corresponding expansion interface;Judgement The file type of the JS injection file;If the file type of the JS injection file is the address URL, pass through the expansion interface The address URL is spliced into link script, the link script is injected into browser page;And if JS injection text The file type of part is JS text, and escape character illegal in the JS text is replaced to obtain by the expansion interface The JS script is injected into the browser page by JS script.
In one embodiment, processor 502 is executing the JS injection file for receiving third party's terminal and being uploaded, Before the step of JS injection file is sent to corresponding expansion interface, also perform the following operations: by for having deposited Class increase method Category characteristic of speech sounds to browser page carry out Interface Expanding, be expanded interface.
In one embodiment, the address URL described is spliced into chain by the expansion interface executing by processor 502 It when the step of pin sheet, performs the following operations: constructing the head of HTML document, obtain initial treatment file;It will The address URL is injected into the main part being located at after head in the initial treatment file, obtains link script.
In one embodiment, processor 502 is executing the described the step of link script is injected into browser page Later, it also performs the following operations: web page contents corresponding with the address URL is obtained according to the link script;By the net Page content is injected into the browser page.
In one embodiment, processor 502 described will illegally be turned by the expansion interface in the JS text executing Adopted character is replaced to obtain JS script, when the JS script is injected into the step of the browser page, is executed as follows Operation: the head of HTML document is constructed, initial treatment file is obtained;Judge in the JS text whether to include pre- If illegal escape character;If including at least one described illegal escape character in the JS text, by the illegal escape word Symbol is shielded, JS text after being handled;By JS text after the processing be injected into initial treatment file be located at head it Main part afterwards obtains the JS script;If in the JS text not including the illegal escape character, the JS text is infused Enter into initial treatment file the main part being located at after head, obtains the JS script.
It will be understood by those skilled in the art that the embodiment of computer equipment shown in Figure 12 is not constituted to computer The restriction of equipment specific composition, in other embodiments, computer equipment may include components more more or fewer than diagram, or Person combines certain components or different component layouts.For example, in some embodiments, computer equipment can only include depositing Reservoir and processor, in such embodiments, the structure and function of memory and processor are consistent with embodiment illustrated in fig. 12, Details are not described herein.
It should be appreciated that in embodiments of the present invention, processor 502 can be central processing unit (Central Processing Unit, CPU), which can also be other general processors, digital signal processor (Digital Signal Processor, DSP), specific integrated circuit (Application Specific Integrated Circuit, ASIC), ready-made programmable gate array (Field-Programmable GateArray, FPGA) or other programmable logic devices Part, discrete gate or transistor logic, discrete hardware components etc..Wherein, general processor can be microprocessor or The processor is also possible to any conventional processor etc..
Computer readable storage medium is provided in another embodiment of the invention.The computer readable storage medium can be with For non-volatile computer readable storage medium.The computer-readable recording medium storage has computer program, wherein calculating Machine program performs the steps of when being executed by processor receives the JS injection file that third party's terminal is uploaded, and the JS is infused Enter file and is sent to corresponding expansion interface;Judge the file type of the JS injection file;If the text of the JS injection file Part type is the address URL, and the address URL is spliced into link script by the expansion interface, and the link script is infused Enter to browser page;And if the file type of JS injection file is JS text, will be described by the expansion interface Illegal escape character is replaced to obtain JS script in JS text, and the JS script is injected into the browser page.
In one embodiment, the JS injection file for receiving third party's terminal and being uploaded, by JS injection file hair It send to before corresponding expansion interface, further includes: pass through the Category characteristic of speech sounds for increasing already present class method Interface Expanding is carried out to browser page, be expanded interface.
In one embodiment, described that the address URL is spliced by link script by the expansion interface, comprising: structure The head for building HTML document obtains initial treatment file;The address URL is injected into the initial treatment text The main part being located at after head in part obtains link script.
In one embodiment, described that the link script is injected into browser page, further includes: according to the chain pin This acquisition web page contents corresponding with the address URL;The web page contents are injected into the browser page.
In one embodiment, it is described by the expansion interface by escape character illegal in the JS text be replaced with JS script is obtained, the JS script is injected into the browser page, comprising: construct the head of HTML document Portion obtains initial treatment file;Judge in the JS text whether to include preset illegal escape character;If in the JS text Including illegal escape character described at least one, the illegal escape character is shielded, JS text after being handled;By institute JS text is injected into the main part being located at after head in initial treatment file after stating processing, obtains the JS script;If described Do not include the illegal escape character in JS text, the JS text is injected into initial treatment file and is located at after head Main part obtains the JS script.
It is apparent to those skilled in the art that for convenience of description and succinctly, foregoing description is set The specific work process of standby, device and unit, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein. Those of ordinary skill in the art may be aware that unit described in conjunction with the examples disclosed in the embodiments of the present disclosure and algorithm Step can be realized with electronic hardware, computer software, or a combination of the two, in order to clearly demonstrate hardware and software Interchangeability generally describes each exemplary composition and step according to function in the above description.These functions are studied carefully Unexpectedly the specific application and design constraint depending on technical solution are implemented in hardware or software.Professional technician Each specific application can be used different methods to achieve the described function, but this realization is it is not considered that exceed The scope of the present invention.
In several embodiments provided by the present invention, it should be understood that disclosed unit and method, it can be with It realizes by another way.For example, the apparatus embodiments described above are merely exemplary, for example, the unit It divides, only logical function partition, there may be another division manner in actual implementation, can also will be with the same function Unit set is at a unit, such as multiple units or components can be combined or can be integrated into another system or some Feature can be ignored, or not execute.In addition, shown or discussed mutual coupling, direct-coupling or communication connection can Be through some interfaces, the indirect coupling or communication connection of device or unit, be also possible to electricity, mechanical or other shapes Formula connection.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple In network unit.Some or all of unit therein can be selected to realize the embodiment of the present invention according to the actual needs Purpose.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit It is that each unit physically exists alone, is also possible to two or more units and is integrated in one unit.It is above-mentioned integrated Unit both can take the form of hardware realization, can also realize in the form of software functional units.
If the integrated unit is realized in the form of SFU software functional unit and sells or use as independent product When, it can store in one storage medium.Based on this understanding, technical solution of the present invention is substantially in other words to existing The all or part of part or the technical solution that technology contributes can be embodied in the form of software products, should Computer software product is stored in a storage medium, including some instructions are used so that a computer equipment (can be Personal computer, terminal or network equipment etc.) it performs all or part of the steps of the method described in the various embodiments of the present invention. And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), magnetic disk or light The various media that can store program code such as disk.
The above description is merely a specific embodiment, but scope of protection of the present invention is not limited thereto, any Those familiar with the art in the technical scope disclosed by the present invention, can readily occur in various equivalent modifications or replace It changes, these modifications or substitutions should be covered by the protection scope of the present invention.Therefore, protection scope of the present invention should be with right It is required that protection scope subject to.

Claims (10)

1. a kind of JS code injection method characterized by comprising
The JS injection file that third party's terminal is uploaded is received, JS injection file is sent to corresponding expansion interface;
Judge the file type of the JS injection file;
If the file type of the JS injection file is the address URL, the address URL is spliced by chain by the expansion interface The link script is injected into browser page by pin sheet;And
If the file type of JS injection file is JS text, by the expansion interface by illegal escape in the JS text Character is replaced to obtain JS script, and the JS script is injected into the browser page.
2. JS code injection method according to claim 1, which is characterized in that described to receive what third party's terminal was uploaded JS injects file, and JS injection file is sent to before corresponding expansion interface, further includes:
Interface Expanding is carried out to browser page by the Category characteristic of speech sounds for increasing already present class method, is obtained To expansion interface.
3. JS code injection method according to claim 1, which is characterized in that it is described will be described by the expansion interface The address URL is spliced into link script, comprising:
The head for constructing HTML document, obtains initial treatment file;
The address URL is injected into the main part after being located at head in the initial treatment file, obtains link script.
4. JS code injection method according to claim 3, which is characterized in that it is described the link script is injected into it is clear It lookes at after the device page, further includes:
Web page contents corresponding with the address URL are obtained according to the link script;
The web page contents are injected into the browser page.
5. JS code injection method according to claim 1, which is characterized in that it is described will be described by the expansion interface Illegal escape character is replaced to obtain JS script in JS text, and the JS script is injected into the browser page, packet It includes:
The head for constructing HTML document, obtains initial treatment file;
Judge in the JS text whether to include preset illegal escape character;
If including at least one described illegal escape character in the JS text, the illegal escape character is shielded, is obtained JS text after to processing;
JS text after the processing is injected into the main part after being located at head in initial treatment file, obtains the JS foot This;
If in the JS text not including the illegal escape character, the JS text is injected into initial treatment file and is located at Main part after head obtains the JS script.
6. a kind of JS code injection device characterized by comprising
File obtaining unit is injected, injects file for receiving the JS that third party's terminal is uploaded, by JS injection file hair It send to corresponding expansion interface;
File type judging unit, for judging the file type of the JS injection file;
First injection unit, if the file type for JS injection file is the address URL, by the expansion interface by institute It states the address URL and is spliced into link script, the link script is injected into browser page;And
Second injection unit, if the file type for JS injection file is JS text, by the expansion interface by institute It states illegal escape character in JS text to be replaced to obtain JS script, the JS script is injected into the browser page.
7. JS code injection device according to claim 6, which is characterized in that further include:
Expansion interface construction unit, for by for already present class increase method Category characteristic of speech sounds to browsing The device page carries out Interface Expanding, and be expanded interface.
8. JS code injection device according to claim 7, which is characterized in that first injection unit, comprising:
First file construction unit obtains initial treatment file for constructing the head of HTML document;
The address URL injection unit, the master for being injected into the address URL after being located at head in the initial treatment file Body portion obtains link script.
9. a kind of computer equipment, including memory, processor and it is stored on the memory and can be on the processor The computer program of operation, which is characterized in that the processor realizes such as claim 1 to 5 when executing the computer program Any one of described in JS code injection method.
10. a kind of computer readable storage medium, which is characterized in that the computer-readable recording medium storage has computer journey Sequence, the computer program make the processor execute such as JS described in any one of claim 1 to 5 when being executed by a processor Code injection method.
CN201910214279.6A 2019-03-20 2019-03-20 JS code injection method, apparatus, computer equipment and storage medium Pending CN110083352A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910214279.6A CN110083352A (en) 2019-03-20 2019-03-20 JS code injection method, apparatus, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910214279.6A CN110083352A (en) 2019-03-20 2019-03-20 JS code injection method, apparatus, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN110083352A true CN110083352A (en) 2019-08-02

Family

ID=67413401

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910214279.6A Pending CN110083352A (en) 2019-03-20 2019-03-20 JS code injection method, apparatus, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110083352A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112416310A (en) * 2019-08-22 2021-02-26 杭州萤石软件有限公司 Function extension method of extended object-oriented software development kit
CN115221529A (en) * 2022-09-14 2022-10-21 杭州天谷信息科技有限公司 Method and system for injecting abnormity of front-end webpage

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102819451A (en) * 2011-06-09 2012-12-12 深圳市财付通科技有限公司 Method and system for calling browser plug-in
CN105094786A (en) * 2014-05-21 2015-11-25 广州市动景计算机科技有限公司 Method and system for customizing page based on JavaScript
CN105183471A (en) * 2015-09-06 2015-12-23 浪潮软件股份有限公司 Method for improving HYBRID application experience based on IOS multi-UIVIEWController
US20160054985A1 (en) * 2014-08-21 2016-02-25 International Business Machines Corporation Evaluating accessibility compliance of a hybrid user interface design
CN107391135A (en) * 2017-07-21 2017-11-24 山东浪潮商用系统有限公司 A kind of view steering method based on Objective C
CN107577483A (en) * 2017-08-31 2018-01-12 武汉斗鱼网络科技有限公司 Component engineering calls method, storage medium, equipment and the system of main works code
CN108009183A (en) * 2016-10-27 2018-05-08 北京京东尚科信息技术有限公司 Method, apparatus and terminal for webpage displayed on the terminals

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102819451A (en) * 2011-06-09 2012-12-12 深圳市财付通科技有限公司 Method and system for calling browser plug-in
CN105094786A (en) * 2014-05-21 2015-11-25 广州市动景计算机科技有限公司 Method and system for customizing page based on JavaScript
US20160054985A1 (en) * 2014-08-21 2016-02-25 International Business Machines Corporation Evaluating accessibility compliance of a hybrid user interface design
CN105183471A (en) * 2015-09-06 2015-12-23 浪潮软件股份有限公司 Method for improving HYBRID application experience based on IOS multi-UIVIEWController
CN108009183A (en) * 2016-10-27 2018-05-08 北京京东尚科信息技术有限公司 Method, apparatus and terminal for webpage displayed on the terminals
CN107391135A (en) * 2017-07-21 2017-11-24 山东浪潮商用系统有限公司 A kind of view steering method based on Objective C
CN107577483A (en) * 2017-08-31 2018-01-12 武汉斗鱼网络科技有限公司 Component engineering calls method, storage medium, equipment and the system of main works code

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112416310A (en) * 2019-08-22 2021-02-26 杭州萤石软件有限公司 Function extension method of extended object-oriented software development kit
CN115221529A (en) * 2022-09-14 2022-10-21 杭州天谷信息科技有限公司 Method and system for injecting abnormity of front-end webpage
CN115221529B (en) * 2022-09-14 2022-12-27 杭州天谷信息科技有限公司 Method and system for injecting abnormity of front-end webpage

Similar Documents

Publication Publication Date Title
US8762556B2 (en) Displaying content on a mobile device
US10817350B2 (en) Method and device for starting external application program in browser
CN105045887B (en) The system and method for mixed mode cross-domain data interaction
CN104572843B (en) The loading method and device of a kind of page
EP3156919A1 (en) Methods for transforming a server side template into a client side template and devices thereof
CN103581232B (en) Web page transmission, web page display device and comprise the system of this device
CN103383687A (en) Page processing method and device
CN110083352A (en) JS code injection method, apparatus, computer equipment and storage medium
CN106980698A (en) Browser static resource loading method, browser program and readable storage medium storing program for executing
CN109144567A (en) Cross-platform webpage rendering method, device, server and storage medium
CN103838558A (en) Website building system and method, website access method and webpage adaption system
CN103019712A (en) Integrated application
CN109508211A (en) A kind of multilingual configuration method, device, system and electronic equipment
CN110750244B (en) Code synchronization method and device, electronic equipment and storage medium
CN107800611A (en) The method and page layout switch device of a kind of page layout switch
CN102497478A (en) Method for cellphone users to access internet quickly
CN101510220A (en) Method, apparatus and system for sending floating page to user side
CN107818171A (en) A kind of page loading method and system based on iframe
US8954345B2 (en) Method and system for advertising using a mobile communication device
KR20120122959A (en) Method and Device for Collecting Web Contents and Computer-readable Recording Medium for the same
CN110058849A (en) Generation method, device, computer equipment and the storage medium of flow chart
CN105279076B (en) A kind of webpage test method and terminal
CN105740239A (en) Translation method and system of character on webpage
CN109862399A (en) It shows the method for rich media information, handle method, computer installation and the computer readable storage medium of rich media information
CN106227517B (en) Primary mobile APP software auto generating method and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20190802