Example of a browser looping page refresh

Source: Internet
Author: User
Tags iweb

classProgram { Public Static voidMain (string[] args) {            intI=0; String[] Urlarray=NewString[] {"http://www.baidu.com/","http://msdn.microsoft.com/","http://www.qidian.com/Default.aspx" }; RefreshPage Repa=NewRefreshPage (0,1, Urlarray,false);  while(I <7) {Repa.                Next (); Repa. Findcurrent="No"; I++; }        }          }
View Code
 classRefreshPage {intcurrentpage; intNextPage;        String[] Urlarray;  PublicString findcurrent="No"; BOOLStop;  PublicRefreshPage (intCurrentPage,intNextPage, string[] Urlarray,BOOLStop) {             This. CurrentPage =currentpage;  This. NextPage =NextPage;  This. Urlarray =Urlarray;  This. Stop =Stop; }         Public voidNext () {shdocvw.shellwindows SW=Newshdocvw.shellwindows ();  while(Findcurrent = ="No")            {                foreach(Shdocvw.internetexplorer IwebinchSW) {                    if(Iweb.LocationURL.StartsWith (Urlarray[currentpage])) {HTMLDocument doc2 
    = Iweb.document asHTMLDocument; Htmlscriptelement Script= (htmlscriptelement) doc2.createelement ("Script"); Script.text="function Newdoc (URL) {window.location.assign (URL)} t=settimeout (\ "Newdoc ("+"'"+ Urlarray[nextpage] +"'"+") \ ", ()"; HTMLBody Body= Doc2.body asHTMLBody; if(Body! =NULL{body.appendchild (ihtmldomnode) script); Findcurrent="Yes"; }                        Else                            Continue; } }} currentpage+=1; NextPage+=1; if(NextPage >=urlarray.length) NextPage=0; if(CurrentPage >=urlarray.length) CurrentPage=0; System.Console.WriteLine (" Current"); }    }
View Code

1. First you need to reference two DLLs

SHDocVw.dll

Mshtml.dll

2. This example is given in the array, the array is stored in the URL that will be iterating, the program accesses the open Web page to look for the value matching the first URL of the array, and adds a script to it, so that the page jumps to another URL, that is,

The next value of the array, which iterates through all the URLs in the array.


3. Variable findcurrent is very important, because it takes time for the browser to open a Web page, and the program reads it, very quickly, if there is no judgment on the variable, the code will never read the URL that is currently being looked for.

while (findcurrent = = "No")

Similarly read to the current URL, but the HTML content has not been load finished, and can not read the body of the HTML, it will not be able to read the HTML body, the following judgment is also very important

if (Body! = null)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.