Javascript ad Simulation

Source: Internet
Author: User

1. Use hidden iframe to load ad pages.
Copy codeThe Code is as follows:
<! At the beginning, we used an invisible framework ID named: framelink -->
<Iframe id = "framelink" name = "framelink" frameBorder = "0" scrolling = "no" width = "0" height = "0"> </iframe>
<! -- Create a connection with the ID "myLink" -->
<A id = 'mylink' target = "framelink"> </a>
<! -- Write a js simulated click A connection with the ID "myLink" and set relevant properties -->
<SCRIPT language = JavaScript type = text/javascript>
<! --
Var GoUrl = "http://www.test.com"; // here is the site to simulate a click.
// If you want to support multiple site simulations, you can set GoUrl as an array. Traverse to perform the following actions.
Var myLink = document. getElementById ("myLink"); // The positioning element is "myLink"
MyLink. href = GoUrl; // set the href attribute of "myLink"
MyLink. click (); // simulate the click action
-->
</SCRIPT>

Using the above Code will cause iframe to load ad pages. If the page is too large, the speed will be very slow,You can use ajax to implement refreshing loads.
Copy codeThe Code is as follows:
Window. onload = function (){
...
Var url = "www.example.com/thiurl"; // the URL of the advertisement
XmlHttp. open ("GET", url, true); // use asynchronous transmission, so that the user does not feel any pause.
XmlHttp. send (null );
XmlHttp. onreadystatechange = function (){
If (xmlHttp. readystate = 4 & xmlHttp. status = 200 ){
// Close the connection after the response is complete.
XmlHttp. close ();
}
}
...
}

Here, we only provide one idea. It may be a better practice! (Note that cross-origin operations cannot be performed)
1. firefox:
Var doc = document.getelementbyid('myiframe'{.content}w.doc ument;
Then doc. getElementById
2. ie:
Var doc = document. getElementById ("myiframe" ).doc ument;
Then doc. getElementById ("iframeTitle ");

Note that cross-origin operations cannot be performed.
This code is used to read the url of the simulated click Based on className = "touPiao" after the page is loaded, for example, #, that is, the current page,
You can also set <a href = "www.javaeye.com" onclick = "showModify (this)" class = "touPiao"> I want to vote for 1111 </a>
The program then simulates all the URLs read by clicking for (var el in els) {according to the for loop.
Finally, a url page will be opened. We can add an empty iframe,
For example, <iframe id = "framelink" name = "framelink" frameBorder = "0" scrolling = "no" width = "0" height = "0"> </iframe>
And modify the link to: <a href = "www.jb51.net" onclick = "showModify (this)" class = "touPiao" target = "framelink"> I want to vote 1111 </a>
In this way, after the page is loaded, the page is simulated and clicked.

Related Article

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.