search
HomeWeb Front-endJS TutorialJavaScript can easily implement the quick message function with just one line of code_javascript skills

Don't worry, the method is very simple, let me talk about its origin first...

In the beginning, the function of quick message can be traced back to the publication [Complete Analysis of AjaxControlToolkitTests Automatic Testing Framework Part 1: Architecture] When I wrote this article, it was purely a by-product of that article. I didn’t pay much attention to it at first. I thought it was just a shortcut for lazy people like me. Later, because there was no prompt, this function would automatically submit the message directly. This aroused the dissatisfaction of several classmates, so later a reminder was added in a prominent position: [Tip: The shortcut link will directly recommend and submit message information. ], the situation was calmed down;

Later, some students may have too advanced mouse and fast combo speed. Every time they use my quick message function, they will put five (I want to like, Passing by, looking forward to the next article, it’s great, I want to recommend it) Click all the shortcut links to enjoy it. Originally, I put so many shortcut links in the hope of providing you with more choices. My intention is that I don’t want you to have every Clicking them all, it turns out that it was originally a lazy tool for lazy people, but it suddenly made people become hardworking. It is really a sin. I can’t stand it when everyone is so hard-working. The comments are like a chat room that’s being flooded with messages. The fundamental reason is that the original program was written too simply without considering the details, so now only two shortcut links are left, and Limitations have been added to the program so that the screen will not be refreshed.

Later, in the past few days, I found that more and more people have added the quick message function to their blogs. When I saw this article (here) yesterday, it was almost intact. Dibaibox copied the code of my quick message function. These applications make me rethink the positioning of the small function of quick message. Objectively speaking, this function is actually a good extension of the existing message function of the blog park! So, instead of letting people reinvent the wheel repeatedly, why not provide a public extension for everyone to use directly?
Based on the above historical reasons, after several hours of hard work, a new version of the universal quick message function was born! The goal of this version is to be simple and universal. Bloggers in other blog parks can directly add the quick message function to their blogs by simply citing it! At present, this function is set to v1.0bate version, and there are still some features to be improved. Future versions will provide more user-defined setting functions, and any new ideas will be gradually added, so if you want to be able to automatically upgrade to new ones in the future, version, just quote my file directly, and all users who use this script will be updated simultaneously.
In fact, the usage is really simple. You only need to fill in the following sentence in the text box of [Backstage Management]->[Settings]->[Top HTML Code].

Copy code The code is as follows:

//Place it in [Backend Management]->[ Settings]->In the text box of [Header Html code]


As shown below:
JavaScript can easily implement the quick message function with just one line of code_javascript skills
Here is the source code of the entire universal quick message function. The time is very short. The code It has not been rigorously tested, so please test it with actual use first. Your criticisms and corrections are welcome! The code is very simple, and I have added a lot of comments, so I won’t go into details here. If you have any questions, just leave a message.
Copy code The code is as follows:

//Author: Justin
//Copyright: Please keep the source when reprinting.
//Version: V1.0 beta
//Last update: 201003300330
//Remarks: If you have any questions, please go to http://www.cnblogs.com/justinw/archive/2010/ 03/30/1700190.html Leave a message to ask questions.

//--begin--jMsg---
function jMsg() { }

//Initialization action
jMsg.prototype.setup = function() {
jMsg.loadEvent(this.combat);
//jMsg.loadEvent(jMsg.msgDIV);
jMsg.msgDIV();
}

//Submit message information
jMsg.prototype.post = function(msg) {
//Here, the HaveUp flag is judged to prevent repeated submission of the same message.
if (window.top.HaveUp) {
alert('You have liked it! Thank you friend:)');
return;
}

var txt = document .getElementById('tbCommentBody');
if (txt != null) {
txt.style.backgroundColor = "#E4F5FF";
var date = new Date();
txt.value = msg;
txt.focus();
//If a quick message has been submitted once, HaveUp is set to true
//HaveUp will be initialized every time you re-enter the page.
window.top.HaveUp = true;
//This is the method used in the blog park to submit messages. This is where you submit messages.
//If you call this method directly on the client without logging in, an error will be thrown internally. (Blog Park code problem, no null judgment)
PostComment();
}
else {
//Currently the Blog Park function restricts the ability to submit comments only after logging in.
//If the tbCommentBody element cannot be found, it can be considered that the current user is not logged in.
alert("You need to log in first to use the blog message function!");
}
}

//Recommendation
jMsg.prototype.recommend = function() {
var diggit = jMsg.getElementsByClassName('diggit');
if ((diggit) && (diggit[0])) {
diggit[0].onclick();
}
else {
alert("Debug: The ClassName of the recommendation button has been renamed!");
}
}

//Objection
jMsg.prototype.combat = function() {
var buryitMsg = function() {
//Currently the recommendation and disapproval of the Blog Park are anonymous. Of course, if you are disapproved, you would like to know the reason.
//This function can only protect against gentlemen but not villains, it just gives a reminder.
var txt = document.getElementById('tbCommentBody');
if (txt != null) {
alert('This student, I really hope to hear your valuable opinions, please enlighten me... .');
txt.style.backgroundColor = "#fe9ab3";
txt.focus();
}
}
var buryit = jMsg.getElementsByClassName('buryit');
if ((buryit) && (buryit[0])) {
jMsg.addEvent(buryit[0], "click", buryitMsg);
}
}

//Recommend while submitting a message
jMsg.prototype.superPost = function(msg) {
this.post(msg);
this.recommend();
}

//Attach onload event
jMsg.loadEvent = function(fn) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = fn;
} else {
window.onload = function() {
oldonload();
fn();
}
}
}

//Additional events
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 DOM elements by ClassName
jMsg.getElementsByClassName = function(n) {
var el = [],
_el = document.getElementsByTagName('*');
for (var i = 0; i if (_el[i].className == n) {
el[el.length] = _el[i];
}
}
return el;
}

//Floating navigation bar for quick messages
jMsg.msgDIV = function() {
//Whether the floating bar appears.
if (!(window.location.href.indexOf(".html") > -1)) return;

//Dynamic calculation of the position of the floating scroll bar
lastScrollY = 0;
var beat = function() {
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.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 = "
[Quick message: Click the link below and you will Submit your message directly.]
JavaScript can easily implement the quick message function with just one line of code_javascript skillsI want to like you! passing
";
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 the content of the floating bar
//todo: Provides an interface for interactive modes other than floating bars
var $jMsg = new jMsg();
$jMsg.setup( ; The user asks "Do you want to recommend this article at the same time?" The original [passing by] link is submitted using the post method. Only the quick message information is submitted and will not be automatically recommended:



Copy code The code is as follows: jMsg.prototype.superPost = function(msg) {
this.post(msg);
//A query function is added here, automatic direct recommendation is not supported
if (confirm("Do you want to recommend this article at the same time?")) {
this.recommend();
}
}


Author: Justin
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Replace String Characters in JavaScriptReplace String Characters in JavaScriptMar 11, 2025 am 12:07 AM

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

Build Your Own AJAX Web ApplicationsBuild Your Own AJAX Web ApplicationsMar 09, 2025 am 12:11 AM

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

10 jQuery Fun and Games Plugins10 jQuery Fun and Games PluginsMar 08, 2025 am 12:42 AM

10 fun jQuery game plugins to make your website more attractive and enhance user stickiness! While Flash is still the best software for developing casual web games, jQuery can also create surprising effects, and while not comparable to pure action Flash games, in some cases you can also have unexpected fun in your browser. jQuery tic toe game The "Hello world" of game programming now has a jQuery version. Source code jQuery Crazy Word Composition Game This is a fill-in-the-blank game, and it can produce some weird results due to not knowing the context of the word. Source code jQuery mine sweeping game

How do I create and publish my own JavaScript libraries?How do I create and publish my own JavaScript libraries?Mar 18, 2025 pm 03:12 PM

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

jQuery Parallax Tutorial - Animated Header BackgroundjQuery Parallax Tutorial - Animated Header BackgroundMar 08, 2025 am 12:39 AM

This tutorial demonstrates how to create a captivating parallax background effect using jQuery. We'll build a header banner with layered images that create a stunning visual depth. The updated plugin works with jQuery 1.6.4 and later. Download the

How do I optimize JavaScript code for performance in the browser?How do I optimize JavaScript code for performance in the browser?Mar 18, 2025 pm 03:14 PM

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Getting Started With Matter.js: IntroductionGetting Started With Matter.js: IntroductionMar 08, 2025 am 12:53 AM

Matter.js is a 2D rigid body physics engine written in JavaScript. This library can help you easily simulate 2D physics in your browser. It provides many features, such as the ability to create rigid bodies and assign physical properties such as mass, area, or density. You can also simulate different types of collisions and forces, such as gravity friction. Matter.js supports all mainstream browsers. Additionally, it is suitable for mobile devices as it detects touches and is responsive. All of these features make it worth your time to learn how to use the engine, as this makes it easy to create a physics-based 2D game or simulation. In this tutorial, I will cover the basics of this library, including its installation and usage, and provide a

Auto Refresh Div Content Using jQuery and AJAXAuto Refresh Div Content Using jQuery and AJAXMar 08, 2025 am 12:58 AM

This article demonstrates how to automatically refresh a div's content every 5 seconds using jQuery and AJAX. The example fetches and displays the latest blog posts from an RSS feed, along with the last refresh timestamp. A loading image is optiona

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft