[JavaScript] you only need a line of code to easily complete the quick message function.

Source: Internet
Author: User

The quick message function is the one that you see floating on the right side. You can use it to directly submit a message and recommend it. Do you want to add this function to your blog?

Don't worry. The method is very simple. Let me talk about its origins first...

At the beginning, the quick message function was traced back to publishing [AjaxControlToolkitTests Automatic Test Framework: Architecture], which was a by-product of the article, I didn't really care about it. I wanted to provide a shortcut for a lazy person like me. Later, I will automatically submit a message because I didn't prompt this function, it also caused dissatisfaction among several students, and then added a note in the eye-catching position:[Note: The quick link will directly recommend and submit the message.]To calm down the situation;

Later, some people may think that the mouse is too advanced and the composite speed is extremely fast. Every time I use my quick message function, I will put five (I want to go top, pass by, and look forward to the next article, great, I want to recommend it) It's just fun to have all the shortcut links. Originally, I put so many shortcuts to provide you with several more options, the intention is that you do not want to point it all over. The result is originally out of the lazy tools provided for the lazy, but it is really a sin to make people suddenly become hardworking. Everyone is so hardworking that I can't afford it. The comment is the same as the screen flushing in the chat room. The root cause is that the original program is too simple to consider details, so now only two shortcuts are left, and restrictions are imposed on the program, so that the screen will not be refreshed.

Later, in the last few days, I found that the quick message function has been added to my blog by more and more people. I saw this article yesterday (here) I copied the code of my quick message function in a white box almost unchanged. These applications allow me to rethink the positioning of the quick message function. Objectively speaking, this function is actually a great extension to the existing message function of the blog Park! So, instead of making people rebuild the wheel repeatedly, why don't we provide a public extension for everyone to use directly?
Based on the above historical reasons, after several hours of efforts, the new version of the general shortcut message function was born! The goal of this version is to make it simple and universal. Bloggers in other blog parks can simply add the quick message function to their blogs by simple reference! At present, this feature is set to v1.0bate, and some features need to be improved. In the future, more user-defined settings will be provided, and any new ideas will be added gradually, therefore, if you want to automatically upgrade the new version in the future, you can directly reference the files here. All users who use this script will update them simultaneously.
In fact, the usage is really simple. You only need to enter the following sentence in the text box of [Background Management]-> [settings]-> [top Html code.

// Go to the [Background Management]-> [settings]-> text box in [top Html code] <script language = "javascript" type = "text/javascript" src = "http://files.cnblogs.com/justinw/jMsg.js "> </script>

As shown in:

Here is the source code of the general shortcut message function. It takes a short time and the Code has not been strictly tested. Therefore, please test it in practice. Thank you for your criticism! The code is very simple. I also added a lot of comments, so I won't go into details here. If you have any questions, just leave a message.

// Author: Justin // Source: http://justin?cnblogs.com//copyright ://transfer.com. // Version: V1.0 beta // last updated: 201003300330 // remarks: if there is a problem, you can give priority to the http://www.cnblogs.com/justinw/archive/2010/03/30/1700190.html leave a message to ask questions. // -- Begin -- jMsg --- function jMsg () {}// initialize jMsg. prototype. setup = function () {jMsg. loadEvent (this. combat); // jMsg. loadEvent (jMsg. msgDIV); jMsg. msgDIV ();} // submit the message jMsg. prototype. post = function (msg) {// identify the HaveUp flag here to prevent repeated submission of the same message. If (window. top. HaveUp) {alert ('You have exceeded! Thank you! :) '); return;} var txt = document. getElementById ('tbcommentbody'); if (txt! = Null) {txt. style. backgroundColor = "# E4F5FF"; var date = new Date (); txt. value = msg; txt. focus (); // if you submit a shortcut message once, HaveUp is set to true // every time you enter the page again, HaveUp will be initialized. Window. top. HaveUp = true; // This is the method used by the blog site to submit a message. Here, the message is submitted. // If you do not log on, call this method directly on the client. An internal error is thrown. (Blog garden code problem, no blank);} else {// currently, the blog garden function is restricted that you can submit a message only after logging on. // If the tbCommentBody element cannot be found, the current user is not logged on. Alert ("You need to log on first to use the blog garden message function! ") ;}/// JMsg is recommended. prototype. recommend = function () {var diggit = jMsg. getElementsByClassName ('diggit '); if (diggit) & (diggit [0]) {diggit [0]. onclick ();} else {alert ("Debug: The ClassName of the Recommendation button is renamed! ") ;}} // Oppose jMsg. prototype. combat = function () {var buryitMsg = function () {// currently, the recommendations and objections of the blog are anonymous. If you are opposed, you certainly want to know the reason. // This function can only be used to prevent the gentleman and avoid the villain. It just gives a prompt. Var txt = document. getElementById ('tbcommentbody'); if (txt! = Null) {alert ('this classmate is very eager to hear your valuable comments. Please enlighten me... '); txt. style. backgroundColor = "# fe9ab3"; txt. focus () ;}var buryit = jMsg. getElementsByClassName ('buryit'); if (buryit) & (buryit [0]) {jMsg. addEvent (buryit [0], "click", buryitMsg) ;}/// jMsg is recommended when you submit a message. prototype. superPost = function (msg) {this. post (msg); this. recommend ();} // attaches the onload event jMsg. loadEvent = function (fn) {var oldonload = window. onload; if (t Ypeof window. onload! = 'Function') {window. onload = fn;} else {window. onload = function () {oldonload (); fn () ;}}// additional event jMsg. addEvent = function (obj, type, fn) {if (obj. addEventListener) obj. addEventListener (type, fn, true); else if (obj. attachEvent) {obj. attachEvent ("on" + type, function () {fn () ;}}// find the DOM element jMsg through ClassName. getElementsByClassName = function (n) {var el = [], _ el = document. getElementsByTagNa Me ('*'); for (var I = 0; I <_ el. length; I ++) {if (_ el [I]. className = n) {el [el. length] = _ el [I] ;}} return el ;}// floating navigation bar jMsg of the shortcut message. msgDIV = function () {// whether a floating bar exists. If (! (Window. location. href. indexOf (". html ")>-1) return; // dynamically calculates the position of the floating scroll bar. lastScrollY = 0; var beat = function () {var diffY; if (document.doc umentElement & document.doc umentElement. scrollTop) diffY = document.doc umentElement. scrollTop; else if (document. body) diffY = document. body. scrollTop else {/* Netscape stuff */} percent =. 1 * (diffY-lastScrollY); if (percent> 0) percent = Math. ceil (percent ); Else percent = Math. floor (percent); document. getElementById ("msgDiv "). style. top = parseInt (document. getElementById ("msgDiv "). style. top) + percent + "px"; lastScrollY = lastScrollY + percent;} msgDivCode = "<div id = \" msgDiv \ "style = 'z-index: 2010; right: 2px; top: 400px; position: absolute; '> <strong> <span style = \ "color: red; font-size: 10pt; \"> [quick message: click the following link to directly submit the message.] </Span> </strong> <br/>  <a onclick = \ "$ jMsg. superPost ('good post! I want to beat you! '); Return false; \ "href = \" ###\ "> <span style = \" font-size: 30pt; \ "> top! </Span> </a> <a onclick = \ "$ jMsg. superPost ('Good! Pass! '); Return false; \ "href = \" ###\ "> <span style = \" font-size: 18pt; \ "> pass by </span> </a> </div>"; document. write (msgDivCode); window. setInterval (beat, 120);} // -- end -- jMsg --- // todo: provides an interface for setting whether to display floating bars. // todo: provides an interface for customizing Floating Bar images // todo: provides an interface for completely customizing Floating Bar content // todo: provides interfaces for interaction modes other than floating bar var $ jMsg = new jMsg (); $ jMsg. setup ();

Update: 201003301250->To maintain the fairness, effectiveness, and world peace of the receng's recommendation ranking mechanismThe superPost method is modified to not automatically recommend articles by default. Instead, a prompt box is displayed asking the user whether to recommend this article at the same time. Instead, the original [pass by] link is submitted using the post method, only the quick message information is submitted and not automatically recommended:

JMsg. prototype. superPost = function (msg) {this. post (msg); // the query function is added here. if (confirm ("do you want to recommend this article at the same time? ") {This. recommend ();}}

Update: 201004020225-> jMsg. js has been updated to V2, and its functions and switching modes have changed significantly. For more information, see the latest version of V2.

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.