WO2015176435A1 - Method and terminal for javascript-based page customization - Google Patents

Method and terminal for javascript-based page customization Download PDF

Info

Publication number
WO2015176435A1
WO2015176435A1 PCT/CN2014/087071 CN2014087071W WO2015176435A1 WO 2015176435 A1 WO2015176435 A1 WO 2015176435A1 CN 2014087071 W CN2014087071 W CN 2014087071W WO 2015176435 A1 WO2015176435 A1 WO 2015176435A1
Authority
WO
WIPO (PCT)
Prior art keywords
page
javascript
custom
file
processed
Prior art date
Application number
PCT/CN2014/087071
Other languages
French (fr)
Chinese (zh)
Inventor
唐俊开
刘欣
Original Assignee
广州市动景计算机科技有限公司
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 广州市动景计算机科技有限公司 filed Critical 广州市动景计算机科技有限公司
Publication of WO2015176435A1 publication Critical patent/WO2015176435A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs

Definitions

  • the present invention relates to the field of mobile internet technologies, and more particularly to a method and terminal for customizing pages based on JavaScript.
  • the browser mode, the novel reader and other smart mode products provide users with customized pages for specific web pages, and the manner in which the web content is customized according to the user's access request is processed by the middleware server. Return to the browser display to the user.
  • FIG. 1 shows a basic flow of an existing browser for customizing a specific webpage content.
  • the middleware server will specify a URL address according to a request initiated by the browser. Visit it again.
  • the middleware server parses the DOM object, the custom business-related JavaScript custom page file is injected into the page, and runs and parsed with the original page; after all customization and rendering are completed, the middleware server will be based on And the custom rules of the JavaScript custom page file, remove the resource code of the non-JavaScript custom page file customization page, and finally form the customized page output to the browser for parsing and display to the user.
  • the process of injecting a JavaScript custom page file into a JavaScript custom page file to dynamically generate a page is done in the middleware server, and the browser itself is only responsible for rendering the final generated page of the middleware server. Since the browser needs to wait for the middleware server to complete the above series of data processing after initiating the customization request, the resource code of the customized page (the JavaScript customized page file customization page) can be obtained. Therefore, the method of customizing the webpage content causes the browser to customize. The response speed of the page is slow, and the browser needs to download all the JavaScript custom page file from the middleware server to customize the resource code of the page, which will also increase the user's traffic expenditure.
  • an object of the present invention is to provide a method and terminal for customizing a page based on JavaScript, to solve the problem that the browser responds slowly when the page is customized, and the browser consumes user traffic during the process of customizing the page.
  • the method for customizing a page based on JavaScript provided by the present invention includes:
  • the terminal provided by the present invention based on a JavaScript customized page includes:
  • the source page code obtaining circuit is configured to obtain a source page code of the to-be-processed webpage according to a web address accessed by the browser;
  • a JavaScript custom page file insertion circuit for inserting a preset JavaScript custom page file in a source page code of a web page to be processed
  • the source page code encapsulation circuit is configured to execute a JavaScript custom page file, and encapsulate the source page code after the JavaScript custom page file into a text string;
  • a service data obtaining circuit configured to obtain service data of a page to be processed according to the encapsulated text string
  • Custom page creation circuitry for creating custom pages based on business data based on custom rules in JavaScript custom page files.
  • Another terminal based on a JavaScript custom page provided by the present invention includes:
  • the memory is configured to store a preset JavaScript custom page file
  • the processor is configured to obtain a source page code of the to-be-processed webpage according to a web address accessed by the browser; a preset JavaScript custom page file stored in the memory, inserting a preset JavaScript custom page file in the source page code of the to-be-processed webpage; executing the JavaScript custom page file, and encapsulating the source page code after the JavaScript customized page file a text string; obtaining business data of the to-be-processed page according to the encapsulated text string; and creating a customized page based on the service data according to the customization rule in the JavaScript customization page file.
  • the present invention also provides a computer readable storage medium carrying a series of instructions to control a computer processor to perform the methods described above.
  • the JavaScript custom page file in the browser is preset when the source page code is downloaded. Perform actions that increase the responsiveness of browser custom pages.
  • FIG. 1 is a schematic diagram of a basic process of customizing a specific webpage content by an existing browser
  • FIG. 2 is a schematic flow chart of a method for customizing a page based on JavaScript according to an embodiment of the present invention
  • FIG. 3 is a schematic flow chart of a method for customizing a page based on JavaScript according to an embodiment of the present invention
  • FIG. 4 is a schematic flow chart of a method for customizing a page based on JavaScript according to another embodiment of the present invention.
  • FIG. 5 is a schematic flowchart diagram of a method for customizing a page based on JavaScript according to still another embodiment of the present invention.
  • FIG. 6 is a schematic flow chart of a method for customizing a page based on JavaScript according to still another embodiment of the present invention.
  • FIG. 7 is a schematic flowchart diagram of a method for customizing a page based on JavaScript according to still another embodiment of the present invention.
  • FIG. 8 is a schematic diagram of interaction of a browser-side injecting a JavaScript custom page file according to an embodiment of the present invention.
  • FIG. 9 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to an embodiment of the present invention.
  • FIG. 10 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to an embodiment of the present invention
  • FIG. 11 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to another embodiment of the present invention.
  • FIG. 12 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to still another embodiment of the present invention.
  • FIG. 13 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to still another embodiment of the present invention.
  • FIG. 14 is a schematic diagram showing the physical structure of a terminal based on a JavaScript customized page according to an embodiment of the present invention.
  • JavaScript custom page file for writing JavaScript code
  • JavaScript code is stored in a JS physical file (that is, XXX.JS file).
  • This JS physical file is preset in the browser, and the JavaScript custom page file is injected into the source page code.
  • the JavaScript code stored in the JS physical file is injected into the original page of the user's browsing.
  • the following JavaScript custom page file is equivalent to the JavaScript code.
  • HTML is an application under the standard universal markup language, which marks each part of the webpage to be displayed by a markup symbol; the webpage file itself is a text file, which can be told to the browser by adding a marker symbol to the text file.
  • the content (such as how to handle the text, how the picture is arranged, how the picture is displayed, etc.).
  • DOM object the Document Object Model (Document Object) Model, DOM) is a programming interface for HTML and XML documents. It provides a structured representation of the document, which can change the content and presentation of the document.
  • ⁇ head> tag used to define the header of the document, which is the container for all header elements.
  • innerHTML A tag property that is used to set or get the HTML inside the object's start and end tags (getting the contents of the HTML's current tag's start and end).
  • Document.write Used in two ways. On the one hand, the page content is created with real-time scripts during the page loading process; on the other hand, the content of this window or new window is created with a time-delay script.
  • ⁇ plaintext> tag The html tag after the tag can be lost its labeling function and will be displayed in the HTML source code.
  • ⁇ /plaintext> tag is to close the tag.
  • the method of injecting a JavaScript customized page file from the middleware server side causes a slow response of the customized page, and increasing the user traffic.
  • the method for customizing the page based on the JavaScript provided by the present invention utilizes the browser itself.
  • FIG. 2 is a flowchart of a method for customizing a page based on a JavaScript according to an embodiment of the present invention. As shown in FIG. 2, a method for customizing a page based on JavaScript according to an embodiment of the present invention firstly starts a user accessing a target URL to a browser.
  • the browser obtains the source page code of the to-be-processed webpage corresponding to the target webpage according to the accessed target web address (step S201); after obtaining the source page code of the to-be-processed webpage, inserting the preset source code code of the to-be-processed webpage a JavaScript custom page file (step S202); executing a JavaScript custom page file, and encapsulating the source page code after the JavaScript custom page file into a text string (step S203); in step S204, acquiring a pending text string according to the packaged text string
  • the business data of the page after acquiring the business data of the to-be-processed page, creating a customized page based on the business data according to the customization rule in the JavaScript customization page file (step S205).
  • step S203 the JavaScript custom page file is executed, and the source page code after the JavaScript customized page file is encapsulated into a text string.
  • step S203a executing the JavaScript customized page file, and customizing the JavaScript by using the label element.
  • the source page code after the page file is encapsulated into a text string.
  • the label element is a plaintext label.
  • step S204 the service data of the page to be processed is obtained according to the encapsulated text string, which may specifically include the following sub-steps:
  • Sub-step S204a Creating a DOM object of the page to be processed according to the encapsulated text string.
  • Sub-step S204b Obtain the service data of the to-be-processed page according to the DOM object of the page to be processed.
  • step S201 the following steps may be included:
  • Step S206 Determine whether the web address accessed by the browser is within a preset white list.
  • the whitelist is pre-set in the browser. If the web address accessed by the browser is in the preset white list, step S202 is performed; if not in the preset white list, step S202 is not performed.
  • step S202 is performed; if not in the preset white list, step S202 is not performed.
  • step S202 a preset JavaScript customization page file is inserted in the source page code of the to-be-processed webpage.
  • step S202a inserting a preset JavaScript after the head tag of the source page code of the to-be-processed webpage.
  • Custom page file For other steps, please refer to Figure 2 and the corresponding text description, which will not be described here.
  • step S205 a customized page based on the service data is created according to the customization rule in the JavaScript customization page file, which may specifically include the following sub-steps:
  • Sub-step S205a Create a DOM object based on the customized data of the business data according to the customization rule in the JavaScript customization page file.
  • Sub-step S205b Loading the DOM object to obtain a customized page.
  • FIG. 8 shows an interaction process of injecting a JavaScript customized page file into the browser side of the embodiment of the present invention, as shown in FIG.
  • the interactive process of injecting JavaScript custom page files into the browser side is:
  • Step S301 Access the target web address.
  • the browser After the user enters the URL and presses the Enter key, the browser starts to connect to the server of the target website. After the connection is successful, the browser starts to download the source page code of the pending page from the target server.
  • the to-be-processed page is the page corresponding to the target URL.
  • Step S302 The browser initiates a request for accessing the target web address to the external core.
  • the browser includes an external core and a kernel.
  • the whitelist is preset in the outer core of the browser, and the target URL accessed by the browser is judged. If the target URL is in the preset whitelist, the external core of the browser will access the target. The request of the URL is notified to the kernel of the browser. If the target URL is not in the default whitelist, the browser's external core does not notify the browser's kernel, and the following operations are not performed.
  • the whitelist is used as a switch to freely expand or shrink the range of custom pages by being able to increase or decrease the list rules, and even to cancel the whitelist immediately (insert a blank JavaScript custom page file).
  • Step S303 The external core of the browser notifies the kernel of the browser.
  • the browser's external core After the destination URL passes the whitelist judgment, the browser's external core notifies the browser's kernel of the request to access the destination URL, and prepares for parsing the target page corresponding to the target URL.
  • Step S304 The kernel of the browser requests the external core of the browser to obtain a JavaScript customized page file.
  • the JavaScript custom page file is also preset in the external core of the browser and is used to parse the pending page corresponding to the target URL.
  • Step S305 The external core of the browser provides a JavaScript customized page file to the kernel of the browser.
  • the JavaScript custom page file is injected into the kernel of the browser; in a specific embodiment of the embodiment, the JavaScript customized page file is scripted. Forms are injected into the kernel of the browser, but are not limited to injecting JavaScript custom page files in the form of scripts.
  • Step S306 The browser kernel parses the page.
  • the browser kernel After injecting the JavaScript custom page file into the browser's kernel, the browser kernel begins to parse the pending page corresponding to the target URL. Parsing the page is to parse the source page code of the page through the injected JavaScript custom page file.
  • the process of parsing the JavaScript custom page file in the source page code is as follows:
  • the JavaScript custom page file that has been injected into the browser kernel is inserted into the ⁇ head> tag as a script, and the inserted JavaScript custom page file is passed through document.write.
  • Method insert a label element: ⁇ plaintext>,
  • the ⁇ plaintext> tag ignores any subsequent tag elements, and converts all tag elements after the ⁇ plaintext> tag into a text string so that it does not parse the HTML, shielding the source page code from the source page code. Downloading and parsing the source page code is done synchronously, so when the original page code is downloaded, the process of parsing the source page code will end. At this point, the JavaScript custom page file will automatically add another tag element ⁇ /plaintext> .
  • the custom page file is inserted into the ⁇ head> tag through the JavaScript, and the tag element after the ⁇ head> tag is stringified, that is, the JavaScript custom page file is After the source page code is not parsed by HTML, it can block the loading of the page, thus saving the traffic when the user accesses the customized page.
  • the ⁇ head> tag is the beginning of a web page. If you want to block all the resources of the page, the JavaScript custom page file should be inserted after the ⁇ head> tag, where the JavaScript custom page file is inserted, depending on the page you want to block. To what extent, if you don't want to block the ⁇ head> tag section, you can insert a JavaScript custom page file after the ⁇ body> tag of the page.
  • Step S307 Extract the data rearrangement page.
  • obtaining the service data of the to-be-processed page refers to acquiring data related to the service according to the needs of the business, for example, extracting the title, body, and the like of the novel.
  • the DOM object of the to-be-processed page is created according to the encapsulated text string; and the service data of the to-be-processed page is obtained according to the DOM object of the to-be-processed page.
  • the DOM object of the custom page based on the business data is created using the innerHTML attribute of the JavaScript custom page file.
  • the source page code on the general page is parsed by the browser. After parsing, a DOM object is created for rendering, and finally displayed on the browser. In the process of rendering the page by the browser, a large amount of resources are consumed. Therefore, in the embodiment of the present invention, the source page code is completely stringified by using a JavaScript custom page file, so that the browser does not parse the source page code, nor does the DOM object be created for rendering, but the DOM object without creating the customized page cannot customize the page.
  • the embodiment of the present invention creates a DOM object based on the customized data of the business data according to the custom rules agreed in the JavaScript customization page file, and saves the created DOM object of the customized page in the memory for the user to use, due to the created customization.
  • the page's DOM object is not rendered on the page, so it can achieve a significant reduction in the use of resources, while customizing the data required by the page for users to use.
  • the custom rules specified in the JavaScript custom page file actually refer to rearranging and combining the data in the original DOM object (the DOM object created by the browser parsing) according to certain requirements, such as the advertisement contained in the original DOM object.
  • the custom rules defined in the JavaScript custom page file according to the embodiment of the present invention are removed; for example, there are numerous links in the original page, or other content that is not associated with the main content, and the JavaScript customized page according to the embodiment of the present invention.
  • the custom rules in the file are also deleted, and the original DOM object is suitable for PC viewing.
  • the original DOM object is changed to a DOM object for creating a customized page based on the business data, which is more suitable for mobile phone viewing.
  • Step S308 The customized page is loaded and displayed on the browser to the user.
  • the interactive process of injecting a JavaScript custom page file by the browser side can be seen that the parsing of the page can be completed independently on the browser side without the operation of the middleware server, thereby improving the response speed of the browser customization page.
  • the foregoing process describes a method for customizing a page based on JavaScript provided by an embodiment of the present invention, and the method of the existing customized page is different from the following:
  • the client After the client injects the JavaScript custom page file, it can immediately block the JavaScript custom page file execution environment of the original page, leaving only the injected JavaScript custom page file environment; while the middleware injects the JavaScript custom page file, there is a shared JavaScript custom page file environment. And issues such as global variable conflicts.
  • the JavaScript development page file in the browser is preset when the source page code is downloaded. Perform actions that increase the responsiveness of browser custom pages.
  • the customized page returned by the middleware server is a simple HTML page, it is a page that provides information services; and the client injects JavaScript to develop a page file scheme, since all are dynamic pages generated by JavaScript to create a page file. , is an exchangeable page, which is more convenient for users to operate on it.
  • the present invention also provides a terminal for customizing a page based on JavaScript.
  • FIG. 9 illustrates a logical structure of a terminal that customizes a page based on JavaScript according to an embodiment of the present invention.
  • the terminal based on the JavaScript custom page provided by the embodiment of the present invention includes a source page code obtaining circuit 410, a JavaScript customized page file inserting circuit 420, a source page code encapsulating circuit 430, a service data obtaining circuit 440, and a customized page.
  • Circuit 450 is created.
  • the source page code obtaining circuit 410 obtains the source page code of the to-be-processed page corresponding to the target web address according to the target web address accessed by the browser; after acquiring the source page code, the JavaScript custom page file inserting circuit 420 inserts a preset JavaScript custom page file in the source page code of the to-be-processed webpage; after inserting the preset JavaScript custompage file, the source page code encapsulation circuit 430 executes the JavaScript custompage file, and the source after the JavaScript customizes the pagefile
  • the page code is encapsulated into a text string to block the source page code after executing the preset JavaScript custom page file; then, the service data obtaining circuit 440 obtains the service data of the to-be-processed page according to the encapsulated text string;
  • the custom page creation circuit 450 creates a customized page based on the business data based on the customization rules in the JavaScript custom page file.
  • the JavaScript customized page file insertion circuit 420 is specifically configured to insert a preset JavaScript customized page file after the head tag of the source page code of the to-be-processed webpage.
  • Figure 10 shows a logical block diagram of one embodiment in accordance with an embodiment of the present invention.
  • the source page code encapsulation circuit 430 includes a tag element encapsulation sub-circuit 431 for encapsulating the source page code following the JavaScript custom page file into a text string using the tag element.
  • the above label element may be a plaintext label
  • the plaintext label may convert the subsequent source page code into a text string
  • Figure 11 illustrates a logical structure in accordance with another embodiment of an embodiment of the present invention.
  • the terminal further includes a white list preset circuit 460 and a white list determining circuit 470.
  • the white list preset circuit 460 presets a white list in the outer core of the browser to make white.
  • the list judging circuit 470 judges the target web address accessed by the browser after the source page code obtaining circuit 410 obtains the source page code of the to-be-processed page corresponding to the target web address according to the target web address accessed by the browser, and the whitelist determining circuit 470 determines the browser.
  • the JavaScript customized page file insertion circuit 420 inserts the source page code of the to-be-processed page corresponding to the target URL.
  • the JavaScript custom page file is set; if the target URL accessed by the browser is not in the preset whitelist, the JavaScript custom page file inserting circuit 420 does not insert the preset JavaScript custom page file.
  • the service data obtaining circuit 440 includes a to-be-processed page DOM object creation sub-circuit 441 and a service data acquisition sub-circuit 442, and the to-be-processed page DOM object creation sub-circuit 441 is used according to the packaged
  • the text string creates a DOM object of the page to be processed
  • the service data obtaining sub-circuit 442 is configured to obtain the service data of the page to be processed according to the DOM object of the page to be processed.
  • the custom page creation circuit 450 includes: a custom page DOM object creation sub-circuit 451 and a custom page DOM object loading sub-circuit 452; a custom page DOM object creation sub-circuit 451 for customizing according to JavaScript A custom rule in the page file creates a DOM object based on the customized page of the business data; the custom page DOM object loading sub-circuit 452 is used to load the DOM object to obtain a customized page.
  • another JavaScript-based custom page-based terminal 500 provided by an embodiment of the present invention includes a processor 510, a memory 520 coupled to the processor 510, and a communication bus 530 for implementing between the components. Connect communication.
  • the terminal 500 also includes a network interface 540 or other user interface 550, which optionally includes a user interface 550, such as a display, keyboard, or pointing device (eg, a mouse, trackball, Touch panel or touch screen).
  • Memory 520 may include high speed RAM memory and may also include non-volatile memory (non-volatile) Memory), such as at least one disk storage.
  • the memory 520 can optionally include at least one storage device located remotely from the processor 510.
  • the memory 520 stores a preset JavaScript custom page file, and also stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof:
  • An operating system 5201 including various system programs for implementing various basic services and processing hardware-based tasks;
  • the application module 5202 includes various applications for implementing various application services.
  • the processor 510 is configured to: Obtaining a source page code of the to-be-processed webpage according to a web address accessed by the browser; extracting a preset JavaScript custompage file stored in the memory, and inserting a preset JavaScript custompage file file in a source page code of the to-be-processed webpage; a JavaScript customization page file, the source page code after the JavaScript custom page file is encapsulated into a text string; the business data of the to-be-processed page is obtained according to the encapsulated text string; and the customization rule in the page file is customized according to the JavaScript , creating a customized page based on the business data.
  • the processor 510 is further configured to: execute the JavaScript custom page file, and package the source page code after the JavaScript customized page file into a text string by using a label element.
  • the label element is a plaintext label.
  • the processor is further configured to: create a DOM object of the to-be-processed page according to the encapsulated text string; and obtain the service data of the to-be-processed page according to the DOM object of the to-be-processed page.
  • the processor is further configured to determine whether the web address accessed by the browser is in a preset white list; if in the preset white list, insert a preset JavaScript customization in the source page code of the to-be-processed webpage.
  • the page file if it is not in the default whitelist, the preset JavaScript custom page file is not inserted.
  • the processor is further configured to insert a preset JavaScript customized page file after the head tag of the source page code of the to-be-processed webpage.
  • the processor is further configured to: create a DOM object based on the customized page of the service data according to a customization rule in the JavaScript customization page file; load the DOM object to obtain a customized page.
  • the JavaScript development page file in the browser is preset when the source page code is downloaded. Perform actions that increase the responsiveness of browser custom pages.
  • the customized page returned by the middleware server is a simple HTML page, it is a page that provides information services; and the client injects JavaScript to develop a page file scheme, since all are dynamic pages generated by JavaScript to create a page file. , is an exchangeable page, which is more convenient for users to operate on it.
  • the embodiment of the invention further provides a computer readable storage medium carrying a series of instructions to control a computer processor to perform the method described above, which is not described herein.

Abstract

A method and system for JavaScript-based page customization, the method comprising: obtaining page source codes of a page to be processed according to a network address accessed by a browser (S201); inserting a preset JavaScript customization page file into the page source codes of the page to be processed (S202); executing the JavaScript customization page file, and encapsulating the page source codes with the JavaScript customization page file inserted therein, into a text string (S203); obtaining service data of the page to be processed according to the encapsulated text string (S204); and establishing a customized page based on the service data according to customization rules in the JavaScript customization page file (S205). Using the abovementioned method and system for JavaScript-based page customization, the traffic of users for viewing a page can be saved and the response speed of browsers in page customization can also be raised.

Description

基于JavaScript定制页面的方法及终端 Method and terminal for customizing page based on JavaScript
【技术领域】[Technical Field]
本发明涉及移动互联网技术领域,更为具体地,涉及一种基于JavaScript定制页面的方法及终端。The present invention relates to the field of mobile internet technologies, and more particularly to a method and terminal for customizing pages based on JavaScript.
【背景技术】 【Background technique】
目前,浏览器的论坛模式、小说阅读器等智能模式的产品,为用户提供的都是针对特定网页的定制页面,其根据用户的访问请求定制网页内容的方式,都是通过中间件服务器处理后返回浏览器显示给用户实现的。At present, the browser mode, the novel reader and other smart mode products provide users with customized pages for specific web pages, and the manner in which the web content is customized according to the user's access request is processed by the middleware server. Return to the browser display to the user.
图1示出了现有的浏览器定制特定网页内容的基本流程,如图1所示,在浏览器发起网页内容定制请求后,中间件服务器会根据浏览器发起的请求,把指定的URL地址访问一遍。在此过程中,中间件服务器解析DOM对象后,把定制业务相关的JavaScript定制页面文件注入到页面中,并且和原页面一起运行和解析;在完成所有的定制和渲染后,中间件服务器会根据和JavaScript定制页面文件约定好的规则条件,移除非JavaScript定制页面文件定制页面的资源代码,最后形成定制页面输出给浏览器解析,并显示给用户。FIG. 1 shows a basic flow of an existing browser for customizing a specific webpage content. As shown in FIG. 1, after the browser initiates a webpage content customization request, the middleware server will specify a URL address according to a request initiated by the browser. Visit it again. In this process, after the middleware server parses the DOM object, the custom business-related JavaScript custom page file is injected into the page, and runs and parsed with the original page; after all customization and rendering are completed, the middleware server will be based on And the custom rules of the JavaScript custom page file, remove the resource code of the non-JavaScript custom page file customization page, and finally form the customized page output to the browser for parsing and display to the user.
从图1中可以看出,从注入JavaScript定制页面文件到JavaScript定制页面文件动态生成页面的过程,都是在中间件服务器中完成的,浏览器自身只需负责渲染中间件服务器最终生成的页面。由于浏览器在发起定制请求后需要等待中间件服务器完成上述一系列数据处理后才能获得定制页面(JavaScript定制页面文件定制页面)的资源代码,因此,这种定制网页内容的方法会导致浏览器定制页面的响应速度慢,同时浏览器需要从中间件服务器端下载全部的JavaScript定制页面文件定制页面的资源代码,也会增加用户的流量支出。As can be seen from Figure 1, the process of injecting a JavaScript custom page file into a JavaScript custom page file to dynamically generate a page is done in the middleware server, and the browser itself is only responsible for rendering the final generated page of the middleware server. Since the browser needs to wait for the middleware server to complete the above series of data processing after initiating the customization request, the resource code of the customized page (the JavaScript customized page file customization page) can be obtained. Therefore, the method of customizing the webpage content causes the browser to customize. The response speed of the page is slow, and the browser needs to download all the JavaScript custom page file from the middleware server to customize the resource code of the page, which will also increase the user's traffic expenditure.
因此,需要一种能够提高响应速度同时降低用户流量的新的定制页面的技术方案。Therefore, there is a need for a new custom page that can increase response speed while reducing user traffic.
【发明内容】 [Summary of the Invention]
鉴于上述问题,本发明的目的是提供一种基于JavaScript定制页面的方法及终端,以解决浏览器在定制页面时响应速度慢的问题,以及浏览器在定制页面过程中耗费用户流量的问题。In view of the above problems, an object of the present invention is to provide a method and terminal for customizing a page based on JavaScript, to solve the problem that the browser responds slowly when the page is customized, and the browser consumes user traffic during the process of customizing the page.
本发明提供的基于JavaScript定制页面的方法,包括:The method for customizing a page based on JavaScript provided by the present invention includes:
根据浏览器访问的网址获取待处理网页的源页面代码;Obtain the source page code of the to-be-processed webpage according to the web address accessed by the browser;
在待处理网页的源页面代码插入预设的JavaScript定制页面文件; Inserting a preset JavaScript custom page file into the source page code of the to-be-processed webpage;
执行JavaScript定制页面文件,将JavaScript定制页面文件后的源页面代码封装成文本字符串;Execute a JavaScript custom page file to encapsulate the source page code after the JavaScript custom page file into a text string;
根据封装后的文本字符串获取待处理页面的业务数据;Obtaining service data of the to-be-processed page according to the encapsulated text string;
根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面。Create custom pages based on business data based on custom rules in the JavaScript custom page file.
本发明提供的基于JavaScript定制页面的终端,包括:The terminal provided by the present invention based on a JavaScript customized page includes:
源页面代码获取电路,用于根据浏览器访问的网址获取待处理网页的源页面代码;The source page code obtaining circuit is configured to obtain a source page code of the to-be-processed webpage according to a web address accessed by the browser;
JavaScript定制页面文件插入电路,用于在待处理网页的源页面代码插入预设的JavaScript定制页面文件;a JavaScript custom page file insertion circuit for inserting a preset JavaScript custom page file in a source page code of a web page to be processed;
源页面代码封装电路,用于执行JavaScript定制页面文件,将JavaScript定制页面文件后的源页面代码封装成文本字符串;The source page code encapsulation circuit is configured to execute a JavaScript custom page file, and encapsulate the source page code after the JavaScript custom page file into a text string;
业务数据获取电路,用于根据封装后的文本字符串获取待处理页面的业务数据;a service data obtaining circuit, configured to obtain service data of a page to be processed according to the encapsulated text string;
定制页面创建电路,用于根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面。Custom page creation circuitry for creating custom pages based on business data based on custom rules in JavaScript custom page files.
本发明提供的另一基于JavaScript定制页面的终端,包括:Another terminal based on a JavaScript custom page provided by the present invention includes:
处理器和与所述处理器耦合的存储器;所述存储器用于存储预设的JavaScript定制页面文件;所述处理器用于根据浏览器访问的网址获取待处理网页的源页面代码;调取所述存储器中存储的预设的JavaScript定制页面文件,在待处理网页的源页面代码插入预设的JavaScript定制页面文件;执行所述JavaScript定制页面文件,将所述JavaScript定制页面文件后的源页面代码封装成文本字符串;根据封装后的文本字符串获取待处理页面的业务数据;根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面。a processor and a memory coupled to the processor; the memory is configured to store a preset JavaScript custom page file; the processor is configured to obtain a source page code of the to-be-processed webpage according to a web address accessed by the browser; a preset JavaScript custom page file stored in the memory, inserting a preset JavaScript custom page file in the source page code of the to-be-processed webpage; executing the JavaScript custom page file, and encapsulating the source page code after the JavaScript customized page file a text string; obtaining business data of the to-be-processed page according to the encapsulated text string; and creating a customized page based on the service data according to the customization rule in the JavaScript customization page file.
本发明还提供一种计算机可读存储介质,所述存储介质承载一系列指令以控制计算机处理器执行上述所述的方法。The present invention also provides a computer readable storage medium carrying a series of instructions to control a computer processor to perform the methods described above.
利用上述根据本发明提供的基于JavaScript定制页面的方法及终端,能够取得以下有益效果:With the above method and terminal based on JavaScript customized page provided according to the present invention, the following beneficial effects can be obtained:
1)由于定制业务相关的JavaScript定制页面文件预先设置在浏览器内,所以不需要从中间件服务器实时下载,可以减少用户在访问页面时的流量。1) Since the custom business-related JavaScript custom page file is pre-set in the browser, there is no need to download it from the middleware server in real time, which can reduce the traffic when the user accesses the page.
2)由于不需要经过中间件服务器将定制业务相关的JavaScript定制页面文件注入到页面中,和页面一起运行和解析,因此,在下载源页面代码时预设在浏览器内的JavaScript定制页面文件开始执行操作,能够提升浏览器定制页面时的响应速度。2) Since the custom business-related JavaScript custom page file is not injected into the page through the middleware server, and is run and parsed together with the page, the JavaScript custom page file in the browser is preset when the source page code is downloaded. Perform actions that increase the responsiveness of browser custom pages.
3)由于将源页面代码全部字符串化,因此浏览器不会解析原页面,也不会创建DOM对象和渲染,因此,能够大幅度减少使用资源。3) Since the source page code is fully stringed, the browser does not parse the original page, nor does it create DOM objects and renders, so the resources can be greatly reduced.
为了实现上述以及相关目的,本发明的一个或多个方面包括后面将详细说明并在权利要求中特别指出的特征。下面的说明以及附图详细说明了本发明的某些示例性方面。然而,这些方面指示的仅仅是可使用本发明的原理的各种方式中的一些方式。此外,本发明旨在包括所有这些方面以及它们的等同物。In order to achieve the above and related ends, one or more aspects of the present invention include the features which are described in detail below and particularly pointed out in the claims. The following description and the annexed drawings set forth in detail However, these aspects are indicative of only some of the various ways in which the principles of the invention may be employed. Furthermore, the invention is intended to cover all such aspects and their equivalents.
【附图说明】 [Description of the Drawings]
通过参考以下结合附图的说明及权利要求书的内容,并且随着对本发明的更全面理解,本发明的其它目的及结果将更加明白及易于理解。在附图中:Other objects and results of the present invention will become more apparent and appreciated from the <RTIgt; In the drawing:
图1为现有的浏览器定制特定网页内容的基本流程示意图;FIG. 1 is a schematic diagram of a basic process of customizing a specific webpage content by an existing browser;
图2为根据本发明实施例的基于JavaScript定制页面的方法的流程示意图;2 is a schematic flow chart of a method for customizing a page based on JavaScript according to an embodiment of the present invention;
图3为根据本发明实施例的一个具体实施方式的基于JavaScript定制页面的方法的流程示意图;3 is a schematic flow chart of a method for customizing a page based on JavaScript according to an embodiment of the present invention;
图4为根据本发明实施例的另一个具体实施方式的基于JavaScript定制页面的方法的流程示意图;4 is a schematic flow chart of a method for customizing a page based on JavaScript according to another embodiment of the present invention;
图5为根据本发明实施例的又一个具体实施方式的基于JavaScript定制页面的方法的流程示意图;FIG. 5 is a schematic flowchart diagram of a method for customizing a page based on JavaScript according to still another embodiment of the present invention; FIG.
图6为根据本发明实施例的又一个具体实施方式的基于JavaScript定制页面的方法的流程示意图;6 is a schematic flow chart of a method for customizing a page based on JavaScript according to still another embodiment of the present invention;
图7为根据本发明实施例的又一个具体实施方式的基于JavaScript定制页面的方法的流程示意图;FIG. 7 is a schematic flowchart diagram of a method for customizing a page based on JavaScript according to still another embodiment of the present invention; FIG.
图8为根据本发明实施例的浏览器端注入JavaScript定制页面文件的交互示意图;FIG. 8 is a schematic diagram of interaction of a browser-side injecting a JavaScript custom page file according to an embodiment of the present invention; FIG.
图9为根据本发明实施例的基于JavaScript定制页面的终端的逻辑结构示意图;9 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to an embodiment of the present invention;
图10为根据本发明实施例的一个具体实施方式的基于JavaScript定制页面的终端的逻辑结构示意图;10 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to an embodiment of the present invention;
图11为根据本发明实施例的另一个具体实施方式的基于JavaScript定制页面的终端的逻辑结构示意图;11 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to another embodiment of the present invention;
图12为根据本发明实施例的又一个具体实施方式的基于JavaScript定制页面的终端的逻辑结构示意图;12 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to still another embodiment of the present invention;
图13为根据本发明实施例的又一个具体实施方式的基于JavaScript定制页面的终端的逻辑结构示意图;FIG. 13 is a schematic diagram showing the logical structure of a terminal based on a JavaScript customized page according to still another embodiment of the present invention; FIG.
图14为根据本发明实施例的基于JavaScript定制页面的终端的实体结构示意图。FIG. 14 is a schematic diagram showing the physical structure of a terminal based on a JavaScript customized page according to an embodiment of the present invention.
在所有附图中相同的标号指示相似或相应的特征或功能。The same reference numerals are used throughout the drawings to refer to the
【具体实施方式】 【detailed description】
在下面的描述中,出于说明的目的,为了提供对一个或多个实施例的全面理解,阐述了许多具体细节。然而,很明显,也可以在没有这些具体细节的情况下实现这些实施例。在其它例子中,为了便于描述一个或多个实施例,公知的结构和设备以方框图的形式示出。In the following description, for the purposes of illustration However, it is apparent that these embodiments may be practiced without these specific details. In other instances, well known structures and devices are shown in block diagram form in order to facilitate describing one or more embodiments.
为了方便理解本发明提供的基于JavaScript定制页面的方法及终端,首先对下述内容中出现的英文进行注解:In order to facilitate the understanding of the method and terminal for customizing a page based on JavaScript provided by the present invention, firstly, the English appearing in the following content is annotated:
JavaScript定制页面文件,为编写的JavaScript代码,JavaScript代码存放在一个JS物理文件(也就是XXX.JS文件)中,这个JS物理文件预设在浏览器中,将JavaScript定制页面文件注入到源页面代码中,就是将保存在JS物理文件中的JavaScript代码注入到用户浏览的原始页面之中,为了表述的方便,下述的JavaScript定制页面文件等同于JavaScript代码。JavaScript custom page file, for writing JavaScript code, JavaScript code is stored in a JS physical file (that is, XXX.JS file). This JS physical file is preset in the browser, and the JavaScript custom page file is injected into the source page code. The JavaScript code stored in the JS physical file is injected into the original page of the user's browsing. For convenience of presentation, the following JavaScript custom page file is equivalent to the JavaScript code.
HTML:是标准通用标记语言下的一个应用,通过标记符号来标记要显示的网页中的各个部分;网页文件本身是一种文本文件,通过在文本文件中添加标记符号,可以告诉浏览器如何显示其中的内容(如:文字如何处理,画面如何安排,图片如何显示等)。HTML: is an application under the standard universal markup language, which marks each part of the webpage to be displayed by a markup symbol; the webpage file itself is a text file, which can be told to the browser by adding a marker symbol to the text file. The content (such as how to handle the text, how the picture is arranged, how the picture is displayed, etc.).
DOM对象:即文档对象模型(Document Object Model,DOM),是一种用于HTML和XML文档的编程接口,给文档提结构化的表示方法,可以改变文档的内容和呈现方式。DOM object: the Document Object Model (Document Object) Model, DOM) is a programming interface for HTML and XML documents. It provides a structured representation of the document, which can change the content and presentation of the document.
<head>标签:用于定义文档的头部,是所有头部元素的容器。<head> tag: used to define the header of the document, which is the container for all header elements.
innerHTML:标签属性,用来设置或获取位于对象起始和结束标签内的HTML(获取HTML当前标签的起始和结束里面的内容)。innerHTML: A tag property that is used to set or get the HTML inside the object's start and end tags (getting the contents of the HTML's current tag's start and end).
document.write:用在两个方面,一方面,页面载入过程中用实时脚本创建页面内容;另一方面,用延时脚本创建本窗口或新窗口的内容。Document.write: Used in two ways. On the one hand, the page content is created with real-time scripts during the page loading process; on the other hand, the content of this window or new window is created with a time-delay script.
<plaintext>标签:可以令该标签后的html标签失去其标示作用,将按照HTML源代码的方式显示。<plaintext> tag: The html tag after the tag can be lost its labeling function and will be displayed in the HTML source code.
</plaintext>标签:是关闭标签。</plaintext> tag: is to close the tag.
以下将结合附图对本发明的具体实施例进行详细描述。Specific embodiments of the present invention will be described in detail below with reference to the drawings.
针对前述现有定制页面方法中,从中间件服务器端注入JavaScript定制页面文件导致定制页面响应速度慢的问题,以及增加用户流量的问题,本发明提供的基于JavaScript定制页面的方法,利用浏览器自身解析JavaScript定制页面文件的能力,把JavaScript定制页面文件的运行环境从中间件服务器搬到浏览器中,以提高访问定制页面时的响应速度,同时降低用户访问定制页面时的流量。In the foregoing existing customized page method, the method of injecting a JavaScript customized page file from the middleware server side causes a slow response of the customized page, and increasing the user traffic. The method for customizing the page based on the JavaScript provided by the present invention utilizes the browser itself. The ability to parse JavaScript custom page files, move the runtime environment of JavaScript custom page files from the middleware server to the browser to improve the response speed when accessing custom pages, while reducing the traffic when users access custom pages.
图2示出了本发明实施例的基于JavaScript定制页面的方法的流程,如图2所示,本发明实施例提供的基于JavaScript定制页面的方法,首先,在用户向浏览器发起访问目标网址的请求时,浏览器根据访问的目标网址获取目标网址对应的待处理网页的源页面代码(步骤S201);在获取待处理网页的源页面代码之后,在待处理网页的源页面代码插入预设的JavaScript定制页面文件(步骤S202);执行JavaScript定制页面文件,将JavaScript定制页面文件后的源页面代码封装成文本字符串(步骤S203);在步骤S204中,根据封装后的文本字符串获取待处理页面的业务数据;在获取待处理页面的业务数据后,根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面(步骤S205)。FIG. 2 is a flowchart of a method for customizing a page based on a JavaScript according to an embodiment of the present invention. As shown in FIG. 2, a method for customizing a page based on JavaScript according to an embodiment of the present invention firstly starts a user accessing a target URL to a browser. When requested, the browser obtains the source page code of the to-be-processed webpage corresponding to the target webpage according to the accessed target web address (step S201); after obtaining the source page code of the to-be-processed webpage, inserting the preset source code code of the to-be-processed webpage a JavaScript custom page file (step S202); executing a JavaScript custom page file, and encapsulating the source page code after the JavaScript custom page file into a text string (step S203); in step S204, acquiring a pending text string according to the packaged text string The business data of the page; after acquiring the business data of the to-be-processed page, creating a customized page based on the business data according to the customization rule in the JavaScript customization page file (step S205).
参见图3,在步骤S203中,即执行JavaScript定制页面文件,将JavaScript定制页面文件后的源页面代码封装成文本字符串,具体可以是步骤S203a:执行JavaScript定制页面文件,利用标签元素将JavaScript定制页面文件后的源页面代码封装成文本字符串。进一步地,标签元素为plaintext标签。其它步骤请参见图2以及相应的文字说明,在此不再进行赘叙。Referring to FIG. 3, in step S203, the JavaScript custom page file is executed, and the source page code after the JavaScript customized page file is encapsulated into a text string. Specifically, the step S203a: executing the JavaScript customized page file, and customizing the JavaScript by using the label element. The source page code after the page file is encapsulated into a text string. Further, the label element is a plaintext label. For other steps, please refer to Figure 2 and the corresponding text description, which will not be described here.
参见图4,在步骤S204中,即根据封装后的文本字符串获取待处理页面的业务数据,具体可以包括如下子步骤:Referring to FIG. 4, in step S204, the service data of the page to be processed is obtained according to the encapsulated text string, which may specifically include the following sub-steps:
子步骤S204a:根据封装后的文本字符串创建待处理页面的DOM对象。Sub-step S204a: Creating a DOM object of the page to be processed according to the encapsulated text string.
子步骤S204b:根据待处理页面的DOM对象获取待处理页面的业务数据。Sub-step S204b: Obtain the service data of the to-be-processed page according to the DOM object of the page to be processed.
参见图5,在步骤S201之后,可以包括如下步骤:Referring to FIG. 5, after step S201, the following steps may be included:
步骤S206:判断浏览器访问的网址是否在预设的白名单内。白名单是预先设置在浏览器内的。如果浏览器访问的网址在预设的白名单内,则进行步骤S202;如果不在预设的白名单内,则不进行步骤S202。其它步骤请参见图2以及相应的文字说明,在此不再进行赘叙。Step S206: Determine whether the web address accessed by the browser is within a preset white list. The whitelist is pre-set in the browser. If the web address accessed by the browser is in the preset white list, step S202 is performed; if not in the preset white list, step S202 is not performed. For other steps, please refer to Figure 2 and the corresponding text description, which will not be described here.
参见图6,在步骤S202中,即在待处理网页的源页面代码插入预设的JavaScript定制页面文件,具体可以是步骤S202a:在待处理网页的源页面代码的head标签后插入预设的JavaScript定制页面文件。其它步骤请参见图2以及相应的文字说明,在此不再进行赘叙。Referring to FIG. 6, in step S202, a preset JavaScript customization page file is inserted in the source page code of the to-be-processed webpage. Specifically, step S202a: inserting a preset JavaScript after the head tag of the source page code of the to-be-processed webpage. Custom page file. For other steps, please refer to Figure 2 and the corresponding text description, which will not be described here.
参见图7,在步骤S205中,即根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面,具体可以包括如下子步骤:Referring to FIG. 7, in step S205, a customized page based on the service data is created according to the customization rule in the JavaScript customization page file, which may specifically include the following sub-steps:
子步骤S205a:根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面的DOM对象。Sub-step S205a: Create a DOM object based on the customized data of the business data according to the customization rule in the JavaScript customization page file.
子步骤S205b:加载DOM对象,得到定制页面。Sub-step S205b: Loading the DOM object to obtain a customized page.
另外,JavaScript定制页面文件中的定制规则将在下面做详细地说明。In addition, the custom rules in the JavaScript custom page file will be explained in detail below.
为了更详细地说明本发明实施例提供的基于JavaScript定制页面的方法,图8示出了本发明实施例的浏览器端注入JavaScript定制页面文件的交互过程,如图8所示,本发明实施例的浏览器端注入JavaScript定制页面文件的交互过程为:In order to explain in more detail the method for customizing a page based on JavaScript provided by the embodiment of the present invention, FIG. 8 shows an interaction process of injecting a JavaScript customized page file into the browser side of the embodiment of the present invention, as shown in FIG. The interactive process of injecting JavaScript custom page files into the browser side is:
步骤S301:访问目标网址。Step S301: Access the target web address.
在用户输入网址,并且按下回车键后,浏览器开始连接目标网站的服务器,连接成功后,浏览器开始从目标服务器下载解析待处理页面的源页面代码。After the user enters the URL and presses the Enter key, the browser starts to connect to the server of the target website. After the connection is successful, the browser starts to download the source page code of the pending page from the target server.
需要说明的是,待处理页面即访问目标网址对应的页面。It should be noted that the to-be-processed page is the page corresponding to the target URL.
步骤S302:浏览器向自身外核发起访问目标网址的请求。Step S302: The browser initiates a request for accessing the target web address to the external core.
浏览器包括外核和内核,白名单预设在浏览器的外核内,对浏览器访问的目标网址进行判断,如果目标网址在预设的白名单内,则浏览器的外核将访问目标网址的请求通知给浏览器的内核,如果目标网址不在预设的白名单内,则浏览器的外核不通知浏览器的内核,也不会进行下述的操作。The browser includes an external core and a kernel. The whitelist is preset in the outer core of the browser, and the target URL accessed by the browser is judged. If the target URL is in the preset whitelist, the external core of the browser will access the target. The request of the URL is notified to the kernel of the browser. If the target URL is not in the default whitelist, the browser's external core does not notify the browser's kernel, and the following operations are not performed.
总而言之,将白名单作为一种开关,通过能够增加或减少名单规则,自由的扩大或缩小定制页面的范围,甚至能够立即取消该白名单(插入空白的JavaScript定制页面文件)。In summary, the whitelist is used as a switch to freely expand or shrink the range of custom pages by being able to increase or decrease the list rules, and even to cancel the whitelist immediately (insert a blank JavaScript custom page file).
步骤S303:浏览器的外核通知浏览器的内核。Step S303: The external core of the browser notifies the kernel of the browser.
在目标网址通过白名单的判断后,浏览器的外核将访问目标网址的请求通知给浏览器的内核,为解析目标网址对应的待处理页面做准备。After the destination URL passes the whitelist judgment, the browser's external core notifies the browser's kernel of the request to access the destination URL, and prepares for parsing the target page corresponding to the target URL.
步骤S304:浏览器的内核向浏览器的外核请求获取JavaScript定制页面文件。Step S304: The kernel of the browser requests the external core of the browser to obtain a JavaScript customized page file.
JavaScript定制页面文件同样预设在浏览器的外核内,用于解析目标网址对应的待处理页面。The JavaScript custom page file is also preset in the external core of the browser and is used to parse the pending page corresponding to the target URL.
步骤S305:浏览器的外核向浏览器的内核提供JavaScript定制页面文件。Step S305: The external core of the browser provides a JavaScript customized page file to the kernel of the browser.
在浏览器的外核将JavaScript定制页面文件提供给浏览器的内核后,将JavaScript定制页面文件注入到浏览器的内核中;在本实施例一个具体实施方式中,将JavaScript定制页面文件以脚本的形式注入到浏览器的内核中,但并不限于以脚本的形式注入JavaScript定制页面文件。After the external core of the browser provides the JavaScript custom page file to the kernel of the browser, the JavaScript custom page file is injected into the kernel of the browser; in a specific embodiment of the embodiment, the JavaScript customized page file is scripted. Forms are injected into the kernel of the browser, but are not limited to injecting JavaScript custom page files in the form of scripts.
步骤S306:浏览器内核解析页面。Step S306: The browser kernel parses the page.
在将JavaScript定制页面文件注入到浏览器的内核之后,浏览器内核开始解析目标网址对应的待处理页面,解析该页面就是通过注入的JavaScript定制页面文件解析该页面的源页面代码。After injecting the JavaScript custom page file into the browser's kernel, the browser kernel begins to parse the pending page corresponding to the target URL. Parsing the page is to parse the source page code of the page through the injected JavaScript custom page file.
在本实施例一个具体实施方式中,JavaScript定制页面文件解析在源页面代码的过程如下:In a specific embodiment of the embodiment, the process of parsing the JavaScript custom page file in the source page code is as follows:
浏览器内核在解析源页面代码遇到<head>标签时,把已经注入到浏览器内核的JavaScript定制页面文件以脚本的形式插入到<head>标签后面,插入的JavaScript定制页面文件通过document.write方法,插入一个标签元素:<plaintext>, <plaintext>标签会忽略其后的任何标签元素,同时把<plaintext>标签后的所有标签元素转化为文本字符串,使其不作HTML解析,起到屏蔽解析源页面代码的作用,由于源页面代码下载和解析源页面代码是同步进行的,所以,当原始页面代码下载完毕时,解析源页面代码的过程也会结束,此时,JavaScript定制页面文件会自动增加另一个标签元素</plaintext>结尾。When the browser kernel encounters the <head> tag in the parsing source page code, the JavaScript custom page file that has been injected into the browser kernel is inserted into the <head> tag as a script, and the inserted JavaScript custom page file is passed through document.write. Method, insert a label element: <plaintext>, The <plaintext> tag ignores any subsequent tag elements, and converts all tag elements after the <plaintext> tag into a text string so that it does not parse the HTML, shielding the source page code from the source page code. Downloading and parsing the source page code is done synchronously, so when the original page code is downloaded, the process of parsing the source page code will end. At this point, the JavaScript custom page file will automatically add another tag element </plaintext> .
由上述解析过程可以看出,在解析页面的过程中,通过JavaScript定制页面文件在<head>标签后插入标签元素,将<head>标签后的标签元素字符串化,也就是将JavaScript定制页面文件后的源页面代码不作HTML解析,可以屏蔽页面的加载,因此能够节省用户访问定制页面时的流量。As can be seen from the above analysis process, in the process of parsing the page, the custom page file is inserted into the <head> tag through the JavaScript, and the tag element after the <head> tag is stringified, that is, the JavaScript custom page file is After the source page code is not parsed by HTML, it can block the loading of the page, thus saving the traffic when the user accesses the customized page.
另一方面,<head>标签是一个网页的开始部分,如果要屏蔽页面的全部资源,JavaScript定制页面文件要插入到<head>标签之后,JavaScript定制页面文件插入到何处,取决于想屏蔽页面到何种程度,如果不希望屏蔽<head>标签部分,可以在网页的<body>标签之后插入JavaScript定制页面文件。On the other hand, the <head> tag is the beginning of a web page. If you want to block all the resources of the page, the JavaScript custom page file should be inserted after the <head> tag, where the JavaScript custom page file is inserted, depending on the page you want to block. To what extent, if you don't want to block the <head> tag section, you can insert a JavaScript custom page file after the <body> tag of the page.
步骤S307:抽取数据重排页面。Step S307: Extract the data rearrangement page.
根据封装后文本字符串获取待处理页面的业务数据,为创建定制页面的DOM对象的做好准备。由于在源页面代码被<plaintext>标签封装成文本字符串后,脚本形式的JavaScript定制页面文件仍会继续运行,此时根据JavaScript定制页面文件中约定的定制规则,创建基于业务数据的定制页面的DOM对象,将创建出的DOM对象保存在内存中,供用户使用,然后加载保存在内存中的DOM对象,重新组成页面,由此,得到定制页面。Get the business data of the page to be processed according to the encapsulated text string, and prepare for creating the DOM object of the customized page. Since the script page form JavaScript custom page file will continue to run after the source page code is encapsulated into a text string by the <plaintext> tag, a custom page based on the business data is created according to the custom rules defined in the JavaScript custom page file. The DOM object saves the created DOM object in memory for the user to use, then loads the DOM object stored in the memory and reconstitutes the page, thereby obtaining a customized page.
需要说明的是,获取待处理页面的业务数据是指根据业务的需要,获取与业务相关的数据,例如抽取小说的标题、正文等等。It should be noted that obtaining the service data of the to-be-processed page refers to acquiring data related to the service according to the needs of the business, for example, extracting the title, body, and the like of the novel.
在本实施例的另一个具体实施方式中,根据封装后的文本字符串创建待处理页面的DOM对象;根据待处理页面的DOM对象获取待处理页面的业务数据。In another embodiment of the present embodiment, the DOM object of the to-be-processed page is created according to the encapsulated text string; and the service data of the to-be-processed page is obtained according to the DOM object of the to-be-processed page.
在本实施例的又一个具体实施方式中,使用JavaScript定制页面文件的innerHTML属性创建基于业务数据的定制页面的DOM对象。In yet another embodiment of this embodiment, the DOM object of the custom page based on the business data is created using the innerHTML attribute of the JavaScript custom page file.
需要说明的是,一般页面上的源页面代码是由浏览器解析,解析后创建一个DOM对象进行渲染,最后显示在浏览器上,在浏览器渲染页面的过程中会消耗大量的资源,因此,本发明实施例利用JavaScript定制页面文件将源页面代码全部字符串化,使浏览器不会解析源页面代码,也不会创建DOM对象进行渲染,但不创建定制页面的DOM对象便无法定制页面,所以,本发明实施例根据JavaScript定制页面文件中约定的定制规则,创建基于业务数据的定制页面的DOM对象,将创建出的定制页面的DOM对象保存在内存中供用户使用,由于创建出的定制页面的DOM对象并不在页面上渲染,因此,能够达到大幅度减少使用资源,同时定制页面需要的数据又可以供用户使用的目的。It should be noted that the source page code on the general page is parsed by the browser. After parsing, a DOM object is created for rendering, and finally displayed on the browser. In the process of rendering the page by the browser, a large amount of resources are consumed. Therefore, In the embodiment of the present invention, the source page code is completely stringified by using a JavaScript custom page file, so that the browser does not parse the source page code, nor does the DOM object be created for rendering, but the DOM object without creating the customized page cannot customize the page. Therefore, the embodiment of the present invention creates a DOM object based on the customized data of the business data according to the custom rules agreed in the JavaScript customization page file, and saves the created DOM object of the customized page in the memory for the user to use, due to the created customization. The page's DOM object is not rendered on the page, so it can achieve a significant reduction in the use of resources, while customizing the data required by the page for users to use.
另一方面,JavaScript定制页面文件中约定的定制规则实际上是指将原始DOM对象(浏览器解析后创建的DOM对象)内的数据按照一定需求重新排列、组合,例如原始DOM对象内包含的广告,根据本发明实施例的JavaScript定制页面文件中约定的定制规则将其去掉;再例如原始页面内有众多链接,或者其他和主要内容关联不大的内容,同样根据本发明实施例的JavaScript定制页面文件中约定的定制规则也将其删除,原始DOM对象适合PC查看,而本发明实施例将原始DOM对象改为创建基于业务数据的定制页面的DOM对象,更适合手机查看。On the other hand, the custom rules specified in the JavaScript custom page file actually refer to rearranging and combining the data in the original DOM object (the DOM object created by the browser parsing) according to certain requirements, such as the advertisement contained in the original DOM object. The custom rules defined in the JavaScript custom page file according to the embodiment of the present invention are removed; for example, there are numerous links in the original page, or other content that is not associated with the main content, and the JavaScript customized page according to the embodiment of the present invention. The custom rules in the file are also deleted, and the original DOM object is suitable for PC viewing. In the embodiment of the present invention, the original DOM object is changed to a DOM object for creating a customized page based on the business data, which is more suitable for mobile phone viewing.
步骤S308:将定制页面加载在浏览器上显示给用户。Step S308: The customized page is loaded and displayed on the browser to the user.
由上述浏览器端注入JavaScript定制页面文件的交互过程可以看出,在浏览器端能够独立完成对页面的解析,无需经过中间件服务器的操作,因此,可以提高浏览器定制页面时的响应速度。The interactive process of injecting a JavaScript custom page file by the browser side can be seen that the parsing of the page can be completed independently on the browser side without the operation of the middleware server, thereby improving the response speed of the browser customization page.
综上所述,上述流程描述了本发明实施例提供的基于JavaScript定制页面的方法,与现有的定制页面的方法区别如下:In summary, the foregoing process describes a method for customizing a page based on JavaScript provided by an embodiment of the present invention, and the method of the existing customized page is different from the following:
1)客户端注入 JavaScript定制页面文件后,可以立即屏蔽原始页面的资源定制和渲染;而中间件服务器需要完整定制一次页面,包括所有资源。1) Client injection Once JavaScript customizes the page file, it can immediately mask the resource customization and rendering of the original page; the middleware server needs to completely customize the page once, including all resources.
2)客户端注入JavaScript定制页面文件后,可以立即屏蔽原始页面的JavaScript定制页面文件执行环境,只保留注入的JavaScript定制页面文件环境;而中间件注入JavaScript定制页面文件则存在共享JavaScript定制页面文件环境以及全局变量冲突等问题。2) After the client injects the JavaScript custom page file, it can immediately block the JavaScript custom page file execution environment of the original page, leaving only the injected JavaScript custom page file environment; while the middleware injects the JavaScript custom page file, there is a shared JavaScript custom page file environment. And issues such as global variable conflicts.
本发明实施例提供的基于JavaScript定制页面的方法还能取得以下有益效果:The method for customizing a page based on JavaScript provided by the embodiment of the present invention can also obtain the following beneficial effects:
1)由于定制业务相关的JavaScript制定页面文件预先设置在浏览器端,不需要从中间件服务器端实时下载,并且,浏览器端注入JavaScript制定页面文件的过程都是在用户的浏览器上进行的,无需向中间件服务器请求服务,用户访问网址时,只需要下载其页面的源页面代码,因此,可以减少用户在访问页面时的流量。1) Since the custom business-related JavaScript development page file is pre-set on the browser side, it does not need to be downloaded from the middleware server side in real time, and the process of injecting JavaScript into the browser side to generate the page file is performed on the user's browser. There is no need to request service from the middleware server. When the user accesses the URL, only the source page code of the page needs to be downloaded, so the traffic of the user when accessing the page can be reduced.
2)由于不需要经过中间件服务器将定制业务相关的JavaScript制定页面文件注入到页面中,和页面一起运行和解析,因此,在下载源页面代码时预设在浏览器内的JavaScript制定页面文件开始执行操作,能够提升浏览器定制页面时的响应速度。2) Since it is not necessary to inject the custom business-related JavaScript development page file into the page through the middleware server, and run and parse with the page, the JavaScript development page file in the browser is preset when the source page code is downloaded. Perform actions that increase the responsiveness of browser custom pages.
3)由于将源页面代码全部字符串化,因此浏览器不会解析页面,也不会创建DOM对象和渲染,因此,能够大幅度减少资源。3) Since the source page code is fully stringed, the browser does not parse the page, nor does it create DOM objects and renders, thus significantly reducing resources.
4)由于中间件服务器返回的已定制页面是一个简洁的HTML页面,是一种提供信息服务的页面;而客户端注入JavaScript制定页面文件方案,由于全部都是由JavaScript制定页面文件生成的动态页面,是一种可交换的页面,更有利于用户对其进行操作。4) Since the customized page returned by the middleware server is a simple HTML page, it is a page that provides information services; and the client injects JavaScript to develop a page file scheme, since all are dynamic pages generated by JavaScript to create a page file. , is an exchangeable page, which is more convenient for users to operate on it.
与上述方法相对应,本发明还提供一种基于JavaScript定制页面的终端。图9示出了根据本发明实施例的基于JavaScript定制页面的终端的逻辑结构。Corresponding to the above method, the present invention also provides a terminal for customizing a page based on JavaScript. FIG. 9 illustrates a logical structure of a terminal that customizes a page based on JavaScript according to an embodiment of the present invention.
如图9所示,本发明实施例所提供的基于JavaScript定制页面的终端包括源页面代码获取电路410、JavaScript定制页面文件插入电路420、源页面代码封装电路430、业务数据获取电路440、定制页面创建电路450。As shown in FIG. 9, the terminal based on the JavaScript custom page provided by the embodiment of the present invention includes a source page code obtaining circuit 410, a JavaScript customized page file inserting circuit 420, a source page code encapsulating circuit 430, a service data obtaining circuit 440, and a customized page. Circuit 450 is created.
当用户向浏览器请求访问目标网址时,源页面代码获取电路410根据浏览器访问的目标网址获取目标网址对应的待处理页面的源页面代码;在获取源页面代码后,JavaScript定制页面文件插入电路420在待处理网页的源页面代码插入预设的JavaScript定制页面文件;在将预设的JavaScript定制页面文件插入后,源页面代码封装电路430执行JavaScript定制页面文件,将JavaScript定制页面文件后的源页面代码封装成文本字符串,以屏蔽执行预设的JavaScript定制页面文件后的源页面代码;然后,业务数据获取电路440根据封装后的文本字符串获取待处理页面的业务数据;在获取待处理页面的业务数据后,定制页面创建电路450根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面。When the user requests the browser to access the target web address, the source page code obtaining circuit 410 obtains the source page code of the to-be-processed page corresponding to the target web address according to the target web address accessed by the browser; after acquiring the source page code, the JavaScript custom page file inserting circuit 420 inserts a preset JavaScript custom page file in the source page code of the to-be-processed webpage; after inserting the preset JavaScript custompage file, the source page code encapsulation circuit 430 executes the JavaScript custompage file, and the source after the JavaScript customizes the pagefile The page code is encapsulated into a text string to block the source page code after executing the preset JavaScript custom page file; then, the service data obtaining circuit 440 obtains the service data of the to-be-processed page according to the encapsulated text string; After the business data of the page, the custom page creation circuit 450 creates a customized page based on the business data based on the customization rules in the JavaScript custom page file.
其中,JavaScript定制页面文件插入电路420具体用于在待处理网页的源页面代码的head标签后插入预设的JavaScript定制页面文件。The JavaScript customized page file insertion circuit 420 is specifically configured to insert a preset JavaScript customized page file after the head tag of the source page code of the to-be-processed webpage.
图10示出了根据本发明实施例的一个具体实施方式的逻辑结构图。Figure 10 shows a logical block diagram of one embodiment in accordance with an embodiment of the present invention.
在如图10所示的具体实施方式中,源页面代码封装电路430包括标签元素封装子电路431,用于利用标签元素将JavaScript定制页面文件后的源页面代码封装成文本字符串。In the embodiment shown in FIG. 10, the source page code encapsulation circuit 430 includes a tag element encapsulation sub-circuit 431 for encapsulating the source page code following the JavaScript custom page file into a text string using the tag element.
具体地,上述标签元素可以为plaintext标签,plaintext标签可以使其后的源页面代码转化被文本字符串。Specifically, the above label element may be a plaintext label, and the plaintext label may convert the subsequent source page code into a text string.
图11示出了根据本发明实施例的另一个具体实施方式的逻辑结构。Figure 11 illustrates a logical structure in accordance with another embodiment of an embodiment of the present invention.
在如图11所示的具体实施方式中,该终端进一步包括白名单预设电路460、白名单判断电路470;通过白名单预设电路460在浏览器的外核内预设白名单,使白名单判断电路470在源页面代码获取电路410根据浏览器访问的目标网址获取目标网址对应的待处理页面的源页面代码后,对浏览器访问的目标网址进行判断,白名单判断电路470判断浏览器访问的目标网址是否在预设的白名单内,如果浏览器访问的目标网址在预设的白名单内,则JavaScript定制页面文件插入电路420在目标网址对应的待处理页面的源页面代码插入预设的JavaScript定制页面文件;如果浏览器访问的目标网址不在预设的白名单内,则JavaScript定制页面文件插入电路420不插入预设的JavaScript定制页面文件。In the embodiment shown in FIG. 11 , the terminal further includes a white list preset circuit 460 and a white list determining circuit 470. The white list preset circuit 460 presets a white list in the outer core of the browser to make white. The list judging circuit 470 judges the target web address accessed by the browser after the source page code obtaining circuit 410 obtains the source page code of the to-be-processed page corresponding to the target web address according to the target web address accessed by the browser, and the whitelist determining circuit 470 determines the browser. Whether the visited destination URL is in the preset whitelist, if the target URL accessed by the browser is in the preset whitelist, the JavaScript customized page file insertion circuit 420 inserts the source page code of the to-be-processed page corresponding to the target URL. The JavaScript custom page file is set; if the target URL accessed by the browser is not in the preset whitelist, the JavaScript custom page file inserting circuit 420 does not insert the preset JavaScript custom page file.
在如图12所示的具体实施方式中,业务数据获取电路440包括待处理页面DOM对象创建子电路441和业务数据获取子电路442,待处理页面DOM对象创建子电路441用于根据封装后的文本字符串创建待处理页面的DOM对象,业务数据获取子电路442用于根据待处理页面的DOM对象获取待处理页面的业务数据。In the specific embodiment shown in FIG. 12, the service data obtaining circuit 440 includes a to-be-processed page DOM object creation sub-circuit 441 and a service data acquisition sub-circuit 442, and the to-be-processed page DOM object creation sub-circuit 441 is used according to the packaged The text string creates a DOM object of the page to be processed, and the service data obtaining sub-circuit 442 is configured to obtain the service data of the page to be processed according to the DOM object of the page to be processed.
在如图13所示的具体实施方式中,定制页面创建电路450包括:定制页面DOM对象创建子电路451和定制页面DOM对象加载子电路452;定制页面DOM对象创建子电路451用于根据JavaScript定制页面文件中的定制规则,创建基于业务数据的定制页面的DOM对象;定制页面DOM对象加载子电路452用于加载DOM对象,得到定制页面。In the specific embodiment shown in FIG. 13, the custom page creation circuit 450 includes: a custom page DOM object creation sub-circuit 451 and a custom page DOM object loading sub-circuit 452; a custom page DOM object creation sub-circuit 451 for customizing according to JavaScript A custom rule in the page file creates a DOM object based on the customized page of the business data; the custom page DOM object loading sub-circuit 452 is used to load the DOM object to obtain a customized page.
参见图14,本发明实施例所提供的另一基于JavaScript定制页面的终端500包括:处理器510、与处理器510耦合的存储器520、通信总线530,通信总线530用于实现这些组件之间的连接通信。该终端500还包括网络接口540或者其他用户接口550,该终端500可选的包含用户接口550,例如显示器、键盘或者点击设备(例如,鼠标,轨迹球(trackball), 触感板或者触感显示屏)。存储器520可能包含高速RAM存储器,也可能还包括非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。存储器520可选的可以包含至少一个位于远离前述处理器510的存储装置。Referring to FIG. 14, another JavaScript-based custom page-based terminal 500 provided by an embodiment of the present invention includes a processor 510, a memory 520 coupled to the processor 510, and a communication bus 530 for implementing between the components. Connect communication. The terminal 500 also includes a network interface 540 or other user interface 550, which optionally includes a user interface 550, such as a display, keyboard, or pointing device (eg, a mouse, trackball, Touch panel or touch screen). Memory 520 may include high speed RAM memory and may also include non-volatile memory (non-volatile) Memory), such as at least one disk storage. The memory 520 can optionally include at least one storage device located remotely from the processor 510.
在一些实施方式中,存储器520存储预设的JavaScript定制页面文件,还存储了如下的元素,可执行模块或者数据结构,或者他们的子集,或者它们的扩展集: In some embodiments, the memory 520 stores a preset JavaScript custom page file, and also stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof:
操作系统5201,包含各种系统程序,用于实现各种基础业务以及处理基于硬件的任务;An operating system 5201, including various system programs for implementing various basic services and processing hardware-based tasks;
应用程序模块5202,包含各种应用程序,用于实现各种应用业务。The application module 5202 includes various applications for implementing various application services.
在本发明实施例中,通过调用存储器5202存储的存储预设的JavaScript定制页面文件、程序或指令,处理器510用于: 根据浏览器访问的网址获取待处理网页的源页面代码;调取所述存储器中存储的预设的JavaScript定制页面文件,在待处理网页的源页面代码插入预设的JavaScript定制页面文件;执行所述JavaScript定制页面文件,将所述JavaScript定制页面文件后的源页面代码封装成文本字符串;根据封装后的文本字符串获取待处理页面的业务数据;根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面。In the embodiment of the present invention, by calling the preset JavaScript custom page file, program or instruction stored in the memory 5202, the processor 510 is configured to: Obtaining a source page code of the to-be-processed webpage according to a web address accessed by the browser; extracting a preset JavaScript custompage file stored in the memory, and inserting a preset JavaScript custompage file file in a source page code of the to-be-processed webpage; a JavaScript customization page file, the source page code after the JavaScript custom page file is encapsulated into a text string; the business data of the to-be-processed page is obtained according to the encapsulated text string; and the customization rule in the page file is customized according to the JavaScript , creating a customized page based on the business data.
在上述各个实施例中,进一步地,所述处理器510还用于:执行所述JavaScript定制页面文件,利用标签元素将所述JavaScript定制页面文件后的源页面代码封装成文本字符串。In the above embodiments, the processor 510 is further configured to: execute the JavaScript custom page file, and package the source page code after the JavaScript customized page file into a text string by using a label element.
其中,所述标签元素为plaintext标签。The label element is a plaintext label.
其中,所述处理器还用于根据封装后的文本字符串创建待处理页面的DOM对象;根据待处理页面的DOM对象获取待处理页面的业务数据。The processor is further configured to: create a DOM object of the to-be-processed page according to the encapsulated text string; and obtain the service data of the to-be-processed page according to the DOM object of the to-be-processed page.
其中,所述处理器还用于判断所述浏览器访问的网址是否在预设的白名单内;如果在预设的白名单内,则在待处理网页的源页面代码插入预设的JavaScript定制页面文件;如果不在预设的白名单内,则不插入预设的JavaScript定制页面文件。The processor is further configured to determine whether the web address accessed by the browser is in a preset white list; if in the preset white list, insert a preset JavaScript customization in the source page code of the to-be-processed webpage. The page file; if it is not in the default whitelist, the preset JavaScript custom page file is not inserted.
其中,所述处理器还用于在待处理网页的源页面代码的head标签后插入预设的JavaScript定制页面文件。The processor is further configured to insert a preset JavaScript customized page file after the head tag of the source page code of the to-be-processed webpage.
其中,所述处理器还用于根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面的DOM对象;加载所述DOM对象,得到定制页面。The processor is further configured to: create a DOM object based on the customized page of the service data according to a customization rule in the JavaScript customization page file; load the DOM object to obtain a customized page.
可见,采用上述方案后:It can be seen that after adopting the above scheme:
1)由于定制业务相关的JavaScript制定页面文件预先设置在浏览器端,不需要从中间件服务器端实时下载,并且,浏览器端注入JavaScript制定页面文件的过程都是在用户的浏览器上进行的,无需向中间件服务器请求服务,用户访问网址时,只需要下载其页面的源页面代码,因此,可以减少用户在访问页面时的流量。1) Since the custom business-related JavaScript development page file is pre-set on the browser side, it does not need to be downloaded from the middleware server side in real time, and the process of injecting JavaScript into the browser side to generate the page file is performed on the user's browser. There is no need to request service from the middleware server. When the user accesses the URL, only the source page code of the page needs to be downloaded, so the traffic of the user when accessing the page can be reduced.
2)由于不需要经过中间件服务器将定制业务相关的JavaScript制定页面文件注入到页面中,和页面一起运行和解析,因此,在下载源页面代码时预设在浏览器内的JavaScript制定页面文件开始执行操作,能够提升浏览器定制页面时的响应速度。2) Since it is not necessary to inject the custom business-related JavaScript development page file into the page through the middleware server, and run and parse with the page, the JavaScript development page file in the browser is preset when the source page code is downloaded. Perform actions that increase the responsiveness of browser custom pages.
3)由于将源页面代码全部字符串化,因此浏览器不会解析页面,也不会创建DOM对象和渲染,因此,能够大幅度减少资源。3) Since the source page code is fully stringed, the browser does not parse the page, nor does it create DOM objects and renders, thus significantly reducing resources.
4)由于中间件服务器返回的已定制页面是一个简洁的HTML页面,是一种提供信息服务的页面;而客户端注入JavaScript制定页面文件方案,由于全部都是由JavaScript制定页面文件生成的动态页面,是一种可交换的页面,更有利于用户对其进行操作。4) Since the customized page returned by the middleware server is a simple HTML page, it is a page that provides information services; and the client injects JavaScript to develop a page file scheme, since all are dynamic pages generated by JavaScript to create a page file. , is an exchangeable page, which is more convenient for users to operate on it.
本发明实施例还提供一种计算机可读存储介质,所述存储介质承载一系列指令以控制计算机处理器执行上述所述的方法,在此不再赘叙。The embodiment of the invention further provides a computer readable storage medium carrying a series of instructions to control a computer processor to perform the method described above, which is not described herein.
如上参照附图以示例的方式描述了根据本发明提出的基于JavaScript定制页面的方法及终端。但是,本领域技术人员应当理解,对于上述本发明所提出的基于JavaScript定制页面的方法及终端,还可以在不脱离本发明内容的基础上对其中的实现细节做出各种改进。因此,本发明的保护范围应当由所附的权利要求书的内容确定。A method and terminal for customizing a page based on JavaScript proposed in accordance with the present invention is described above by way of example with reference to the accompanying drawings. However, it should be understood by those skilled in the art that various improvements can be made to the implementation details of the method and terminal based on the JavaScript customization method proposed by the present invention based on the content of the present invention. Therefore, the scope of the invention should be determined by the content of the appended claims.

Claims (22)

  1. 一种基于JavaScript定制页面的方法,其中,所述方法包括:A method for customizing a page based on JavaScript, wherein the method comprises:
    根据浏览器访问的网址获取待处理网页的源页面代码;Obtain the source page code of the to-be-processed webpage according to the web address accessed by the browser;
    在待处理网页的源页面代码插入预设的JavaScript定制页面文件; Inserting a preset JavaScript custom page file into the source page code of the to-be-processed webpage;
    执行所述JavaScript定制页面文件,将所述JavaScript定制页面文件后的源页面代码封装成文本字符串;Executing the JavaScript custom page file, and encapsulating the source page code after the JavaScript custom page file into a text string;
    根据封装后的文本字符串获取待处理页面的业务数据;Obtaining service data of the to-be-processed page according to the encapsulated text string;
    根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面。A customized page based on the business data is created according to the customization rules in the JavaScript custom page file.
  2. 如权利要求1所述的基于JavaScript定制页面的方法,其中,所述执行所述JavaScript定制页面文件,将所述JavaScript定制页面文件后的源页面代码封装成文本字符串的步骤,包括:执行所述JavaScript定制页面文件,利用标签元素将所述JavaScript定制页面文件后的源页面代码封装成文本字符串。The method for customizing a page based on JavaScript according to claim 1, wherein the step of executing the JavaScript custom page file and encapsulating the source page code after the JavaScript custom page file into a text string comprises: The JavaScript custom page file encapsulates the source page code of the JavaScript custom page file into a text string using a tag element.
  3. 如权利要求2所述的基于JavaScript定制页面的方法,其中,所述标签元素为plaintext标签。The method of customizing a page based on JavaScript according to claim 2, wherein the tag element is a plaintext tag.
  4. 如权利要求1所述的基于JavaScript定制页面的方法,其中,所述根据封装后的文本字符串获取待处理页面的业务数据的步骤,包括:The method for customizing a page based on a JavaScript according to claim 1, wherein the step of acquiring the service data of the page to be processed according to the encapsulated text string comprises:
    根据封装后的文本字符串创建待处理页面的DOM对象;Create a DOM object of the to-be-processed page according to the encapsulated text string;
    根据待处理页面的DOM对象获取待处理页面的业务数据。The service data of the to-be-processed page is obtained according to the DOM object of the to-be-processed page.
  5. 如权利要求1所述的基于JavaScript定制页面的方法,其中,所述根据浏览器访问的网址获取待处理网页的源页面代码的步骤之后,包括:The method for customizing a page based on a JavaScript according to claim 1, wherein the step of obtaining the source page code of the web page to be processed according to the web address accessed by the browser comprises:
    判断所述浏览器访问的网址是否在预设的白名单内;Determining whether the web address accessed by the browser is in a preset white list;
    如果在预设的白名单内,则在待处理网页的源页面代码插入预设的JavaScript定制页面文件;如果不在预设的白名单内,则不插入预设的JavaScript定制页面文件。If it is in the preset whitelist, the default JavaScript custom page file is inserted in the source page code of the to-be-processed webpage; if it is not in the preset whitelist, the preset JavaScript custompage file is not inserted.
  6. 如权利要求1所述的基于JavaScript定制页面的方法,其中,所述在待处理网页的源页面代码插入预设的JavaScript定制页面文件的步骤,包括:在待处理网页的源页面代码的head标签后插入预设的JavaScript定制页面文件。The method for customizing a page based on JavaScript according to claim 1, wherein the step of inserting a preset JavaScript custom page file in the source page code of the to-be-processed webpage includes: a head tag of a source page code of the to-be-processed webpage After inserting the default JavaScript custom page file.
  7. 如权利要求1所述的基于JavaScript定制页面的方法,其中,所述根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面的步骤,包括:The method for customizing a page based on JavaScript according to claim 1, wherein the step of creating a customized page based on the service data according to a customization rule in the JavaScript customization page file comprises:
    根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面的DOM对象;Creating a DOM object based on the customized page of the business data according to a customization rule in the JavaScript customization page file;
    加载所述DOM对象,得到定制页面。Load the DOM object to get a custom page.
  8. 一种基于JavaScript定制页面的终端,其中,所述终端包括:A terminal based on a JavaScript customized page, wherein the terminal comprises:
    源页面代码获取电路,用于根据浏览器访问的网址获取待处理网页的源页面代码;The source page code obtaining circuit is configured to obtain a source page code of the to-be-processed webpage according to a web address accessed by the browser;
    JavaScript定制页面文件插入电路,用于在待处理网页的源页面代码插入预设的JavaScript定制页面文件;a JavaScript custom page file insertion circuit for inserting a preset JavaScript custom page file in a source page code of a web page to be processed;
    源页面代码封装电路,用于执行所述JavaScript定制页面文件,将所述JavaScript定制页面文件后的源页面代码封装成文本字符串;a source page code encapsulating circuit, configured to execute the JavaScript custom page file, and encapsulate the source page code after the JavaScript custom page file into a text string;
    业务数据获取电路,用于根据封装后的文本字符串获取待处理页面的业务数据;a service data obtaining circuit, configured to obtain service data of a page to be processed according to the encapsulated text string;
    定制页面创建电路,用于根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面。A custom page creation circuit for creating a customized page based on the business data according to a customization rule in the JavaScript customization page file.
  9. 如权利要求8所述的基于JavaScript定制页面的终端,其中,A JavaScript-based custom page-based terminal according to claim 8, wherein
    所述源页面代码封装电路包括标签元素封装子电路,所述标签元素封装子电路用于利用标签元素将所述JavaScript定制页面文件后的源页面代码封装成文本字符串。The source page code encapsulation circuit includes a tag element encapsulation sub-circuit for encapsulating the source page code after the JavaScript custom page file into a text string using a tag element.
  10. 如权利要求9的所述的基于JavaScript定制页面的终端,其中,A JavaScript-based custom page-based terminal according to claim 9, wherein
    所述标签元素为plaintext标签。The label element is a plaintext label.
  11. 如权利要求8所述的基于JavaScript定制页面的终端,其中,A JavaScript-based custom page-based terminal according to claim 8, wherein
    所述终端还包括白名单预设电路、白名单判断电路;The terminal further includes a white list preset circuit and a white list judgment circuit;
    所述白名单预设电路,用于预设白名单;The white list preset circuit is configured to preset a white list;
    所述白名单判断电路,用于在根据浏览器访问的网址获取待处理网页的源页面代码之后,判断所述浏览器访问的网址是否在预设的白名单内;The whitelist determining circuit is configured to determine, after obtaining the source page code of the to-be-processed webpage according to the webpage accessed by the browser, whether the webpage accessed by the browser is in a preset whitelist;
    所述JavaScript定制页面文件插入电路,用于如果在预设的白名单内,则在待处理网页的源页面代码插入预设的JavaScript定制页面文件;The JavaScript custom page file insertion circuit is configured to insert a preset JavaScript custom page file in a source page code of the to-be-processed webpage if it is in a preset whitelist;
    如果不在预设的白名单内,则不插入预设的JavaScript定制页面文件。If it is not in the default whitelist, the default JavaScript custom page file is not inserted.
  12. 如权利要求8所述的基于JavaScript定制页面的终端,其中,A JavaScript-based custom page-based terminal according to claim 8, wherein
    所述业务数据获取电路包括待处理页面DOM对象创建子电路和业务数据获取子电路,The service data obtaining circuit includes a to-be-processed page DOM object creation sub-circuit and a service data acquisition sub-circuit,
    所述待处理页面DOM对象创建子电路,用于根据封装后的文本字符串创建待处理页面的DOM对象,The to-be-processed page DOM object creation sub-circuit is configured to create a DOM object of the to-be-processed page according to the encapsulated text string.
    所述业务数据获取子电路,用于根据待处理页面的DOM对象获取待处理页面的业务数据。The service data obtaining sub-circuit is configured to obtain service data of a page to be processed according to a DOM object of a page to be processed.
  13. 如权利要求8所述的基于JavaScript定制页面的终端,其中,所述JavaScript定制页面文件插入电路具体用于在待处理网页的源页面代码的head标签后插入预设的JavaScript定制页面文件。The JavaScript custom page-based terminal of claim 8, wherein the JavaScript custom page file insertion circuit is specifically configured to insert a preset JavaScript custom page file after the head tag of the source page code of the to-be-processed web page.
  14. 如权利要求8所述的基于JavaScript定制页面的终端,其中,所述定制页面创建电路包括:定制页面DOM对象创建子电路和定制页面DOM对象加载子电路;The JavaScript custom page-based terminal according to claim 8, wherein the customized page creation circuit comprises: a custom page DOM object creation sub-circuit and a custom page DOM object loading sub-circuit;
    所述定制页面DOM对象创建子电路,用于根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面的DOM对象;The custom page DOM object creation sub-circuit is configured to create a DOM object based on the customized page of the service data according to a customization rule in the JavaScript customization page file;
    所述定制页面DOM对象加载子电路,用于加载所述DOM对象,得到定制页面。The custom page DOM object loading sub-circuit is configured to load the DOM object to obtain a customized page.
  15. 一种基于JavaScript定制页面的终端,其中,所述终端包括:处理器和与所述处理器耦合的存储器;A terminal based on a JavaScript custom page, wherein the terminal comprises: a processor and a memory coupled to the processor;
    所述存储器用于存储预设的JavaScript定制页面文件;The memory is configured to store a preset JavaScript custom page file;
    所述处理器用于根据浏览器访问的网址获取待处理网页的源页面代码;调取所述存储器中存储的预设的JavaScript定制页面文件,在待处理网页的源页面代码插入预设的JavaScript定制页面文件;执行所述JavaScript定制页面文件,将所述JavaScript定制页面文件后的源页面代码封装成文本字符串;根据封装后的文本字符串获取待处理页面的业务数据;根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面。The processor is configured to obtain a source page code of the to-be-processed webpage according to a web address accessed by the browser; retrieve a preset JavaScript custompage file stored in the memory, and insert a preset JavaScript customization in a source page code of the to-be-processed webpage. a page file; executing the JavaScript custom page file, encapsulating the source page code of the JavaScript custom page file into a text string; obtaining business data of the to-be-processed page according to the encapsulated text string; and customizing the page according to the JavaScript A custom rule in the file that creates a customized page based on the business data.
  16. 如权利要求15所述的基于JavaScript定制页面的终端,其中,所述处理器还用于执行所述JavaScript定制页面文件,利用标签元素将所述JavaScript定制页面文件后的源页面代码封装成文本字符串。The JavaScript-based custom page-based terminal of claim 15, wherein the processor is further configured to execute the JavaScript custom page file, and package the source page code of the JavaScript customized page file into a text character by using a label element. string.
  17. 如权利要求16所述的基于JavaScript定制页面的终端,其中,所述标签元素为plaintext标签。The JavaScript-based custom page-based terminal of claim 16, wherein the tag element is a plaintext tag.
  18. 如权利要求15所述的基于JavaScript定制页面的终端,其中,所述处理器还用于根据封装后的文本字符串创建待处理页面的DOM对象;根据待处理页面的DOM对象获取待处理页面的业务数据。The JavaScript custom page-based terminal according to claim 15, wherein the processor is further configured to: create a DOM object of the to-be-processed page according to the encapsulated text string; and acquire the to-be-processed page according to the DOM object of the to-be-processed page. Business data.
  19. 如权利要求15所述的基于JavaScript定制页面的终端,其中,所述处理器还用于判断所述浏览器访问的网址是否在预设的白名单内;如果在预设的白名单内,则在待处理网页的源页面代码插入预设的JavaScript定制页面文件;如果不在预设的白名单内,则不插入预设的JavaScript定制页面文件。The JavaScript custom page-based terminal according to claim 15, wherein the processor is further configured to determine whether the web address accessed by the browser is in a preset white list; if in the preset white list, The default JavaScript custom page file is inserted in the source page code of the to-be-processed webpage; if it is not in the preset whitelist, the preset JavaScript custompage file is not inserted.
  20. 如权利要求15所述的基于JavaScript定制页面的终端,其中,所述处理器还用于在待处理网页的源页面代码的head标签后插入预设的JavaScript定制页面文件。The JavaScript custom page-based terminal according to claim 15, wherein the processor is further configured to insert a preset JavaScript custom page file after the head tag of the source page code of the to-be-processed webpage.
  21. 如权利要求15所述的基于JavaScript定制页面的终端,其中,所述处理器还用于根据所述JavaScript定制页面文件中的定制规则,创建基于所述业务数据的定制页面的DOM对象;加载所述DOM对象,得到定制页面。The JavaScript-based custom page-based terminal of claim 15, wherein the processor is further configured to create a DOM object based on the customized page of the service data according to a customization rule in the JavaScript customization page file; Describe the DOM object and get a custom page.
  22. 一种计算机可读存储介质,其中,所述存储介质承载一系列指令以控制计算机处理器执行如权利要求1所述的方法。A computer readable storage medium, wherein the storage medium carries a series of instructions to control a computer processor to perform the method of claim 1.
PCT/CN2014/087071 2014-05-21 2014-09-22 Method and terminal for javascript-based page customization WO2015176435A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410217132.X 2014-05-21
CN201410217132.XA CN105094786B (en) 2014-05-21 2014-05-21 Method and system based on JavaScript customized web page

Publications (1)

Publication Number Publication Date
WO2015176435A1 true WO2015176435A1 (en) 2015-11-26

Family

ID=54553321

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/087071 WO2015176435A1 (en) 2014-05-21 2014-09-22 Method and terminal for javascript-based page customization

Country Status (2)

Country Link
CN (1) CN105094786B (en)
WO (1) WO2015176435A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105653668A (en) * 2015-12-29 2016-06-08 武汉理工大学 Webpage content analysis and extraction optimization method based on DOM Tree in cloud environment
CN112579068A (en) * 2019-09-30 2021-03-30 北京国双科技有限公司 Code generation method, device, storage medium and equipment
CN113448543A (en) * 2021-01-20 2021-09-28 北京新氧科技有限公司 Page processing method, device, equipment and system
CN114217866A (en) * 2021-11-08 2022-03-22 阿里健康科技(中国)有限公司 Applet using method and device and electronic equipment

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106055564B (en) * 2016-05-18 2019-03-12 平安科技(深圳)有限公司 Page loading method and device
CN106383710A (en) * 2016-09-19 2017-02-08 成都知道创宇信息技术有限公司 Webpage embedding method
CN107016021A (en) * 2016-11-08 2017-08-04 阿里巴巴集团控股有限公司 Page loading method, client, system and electronic equipment
CN106897215A (en) * 2017-01-20 2017-06-27 华南理工大学 A kind of method gathered based on WebView webpages loading performance and user behavior flow data
CN107729516A (en) * 2017-10-26 2018-02-23 北京百度网讯科技有限公司 Single page application methods of exhibiting and device, server, equipment and computer-readable recording medium
CN108270644B (en) * 2017-12-15 2020-11-24 广东智媒云图科技股份有限公司 Page flow monitoring method based on multiple platforms, electronic equipment and storage medium
CN108616538A (en) * 2018-04-28 2018-10-02 北京网思科平科技有限公司 Attacker's formation gathering method, system, terminal, server and its storage medium
CN108874875A (en) * 2018-04-28 2018-11-23 北京微播视界科技有限公司 The asynchronous loading method of web page contents, device, readable storage medium storing program for executing and terminal
CN110083352A (en) * 2019-03-20 2019-08-02 平安普惠企业管理有限公司 JS code injection method, apparatus, computer equipment and storage medium
CN111680200A (en) * 2020-04-27 2020-09-18 平安国际智慧城市科技股份有限公司 Method, device and equipment for collecting user behavior data and storage medium
CN111680247B (en) * 2020-04-28 2024-04-05 深圳赛安特技术服务有限公司 Local calling method, device and equipment of webpage character strings and storage medium
CN113343159B (en) * 2021-08-06 2021-11-12 万商云集(成都)科技股份有限公司 Method and system for rapidly acquiring data from any channel, analyzing and storing data

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101414257A (en) * 2008-11-13 2009-04-22 成都市华为赛门铁克科技有限公司 Method, device and terminal for implementing software interface
US20100318976A1 (en) * 2009-06-11 2010-12-16 Webtrends, Inc. Method and system for constructing a customized web analytics application
US20120131473A1 (en) * 2010-11-23 2012-05-24 Axeda Corporation Scripting web services
CN102737128A (en) * 2012-06-20 2012-10-17 深圳市远行科技有限公司 Dynamic webpage processing method and device based on browser
CN103530338A (en) * 2013-10-01 2014-01-22 北界创想(北京)软件有限公司 Frame for carrying out page rendering on calculation equipment and page generation method

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012071037A2 (en) * 2010-11-23 2012-05-31 Biron Joseph L Scripting web services
CN102662737B (en) * 2012-03-14 2014-06-11 优视科技有限公司 Calling method and device of extension program
CN102693280B (en) * 2012-04-28 2014-08-13 广州市动景计算机科技有限公司 Webpage browsing method, WebApp framework, method and device for executing JavaScript, and mobile terminal

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101414257A (en) * 2008-11-13 2009-04-22 成都市华为赛门铁克科技有限公司 Method, device and terminal for implementing software interface
US20100318976A1 (en) * 2009-06-11 2010-12-16 Webtrends, Inc. Method and system for constructing a customized web analytics application
US20120131473A1 (en) * 2010-11-23 2012-05-24 Axeda Corporation Scripting web services
CN102737128A (en) * 2012-06-20 2012-10-17 深圳市远行科技有限公司 Dynamic webpage processing method and device based on browser
CN103530338A (en) * 2013-10-01 2014-01-22 北界创想(北京)软件有限公司 Frame for carrying out page rendering on calculation equipment and page generation method

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105653668A (en) * 2015-12-29 2016-06-08 武汉理工大学 Webpage content analysis and extraction optimization method based on DOM Tree in cloud environment
CN112579068A (en) * 2019-09-30 2021-03-30 北京国双科技有限公司 Code generation method, device, storage medium and equipment
CN113448543A (en) * 2021-01-20 2021-09-28 北京新氧科技有限公司 Page processing method, device, equipment and system
CN113448543B (en) * 2021-01-20 2024-02-02 北京新氧科技有限公司 Page processing method, device, equipment and system
CN114217866A (en) * 2021-11-08 2022-03-22 阿里健康科技(中国)有限公司 Applet using method and device and electronic equipment
CN114217866B (en) * 2021-11-08 2023-09-19 阿里健康科技(中国)有限公司 Application method and device of applet and electronic equipment

Also Published As

Publication number Publication date
CN105094786A (en) 2015-11-25
CN105094786B (en) 2019-05-28

Similar Documents

Publication Publication Date Title
WO2015176435A1 (en) Method and terminal for javascript-based page customization
US8935358B2 (en) Interactive server side components
US9460222B2 (en) System for rewriting dynamically generated uniform resource locators in proxied hyper text markup language content in accordance with proxy server rules
KR20200043467A (en) Method and terminal device for extracting web page content
US7783967B1 (en) Packaging web content for reuse
US20120173967A1 (en) Method and device for cascading style sheet (css) selector matching
KR20080053293A (en) Initial server-side content rendering for client-script web pages
JP2004519116A (en) System and method for television enhancement
KR20040107445A (en) Web page rendering mechanism using external programmatic themes
JP2011003182A (en) Keyword display method and system thereof
CN101876897A (en) System and method used for processing Widget on Web browser
CN102663050B (en) Method and device for processing electronic book data
CN110647699A (en) Web page rendering method and device, computer equipment and storage medium
WO2022048141A9 (en) Image processing method and apparatus, and computer readable storage medium
WO2020048424A1 (en) Webpage construction method, apparatus and storage medium
WO2013091556A1 (en) Browser based application program extension method and device
WO2017041544A1 (en) Method and device for acquiring web page content in android system
CN102193789B (en) Method and equipment for realizing configurable skip link
JP2009031960A (en) Technology for relaying communication between client device and server device
CN116431155A (en) Front-end application construction method, medium, device and computing equipment
WO2016108677A1 (en) Apparatus and method for outputting web content
CN113297425B (en) Document conversion method, device, server and storage medium
CN101441628A (en) Intelligent client terminal website system based on desktop application program
CN111221590B (en) Method for acquiring URL of browser with chrome as kernel
US20170083481A1 (en) Method and apparatus for rendering a screen-representation of an electronic document

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14892606

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 17.03.2017)

122 Ep: pct application non-entry in european phase

Ref document number: 14892606

Country of ref document: EP

Kind code of ref document: A1