


Modified version of Javascript operation URL function_javascript skills
Summarized some methods and compressed it into a function object with only a few dozen lines of code. The usage method is simple and clear
Save as ojbUrl.js
/*
Note: This code can be copied, modified and used freely, but please keep the author information!
Author: Kevin WebSite: http://iulog.com/ QQ:251378427
JS operation URL function usage instructions:
Initialize var myurl=new objURL(); //You can also customize the URL: var myurl=new objURL('http://www.jb51.net');
Read the url parameter value var val=myurl.get('abc'); // Read the value of the parameter abc
Set url parameter myurl.set("arg",data); //Add/modify the value of an arg parameter to data
Remove url parameter myurl.remove("arg"); //Remove arg parameter
Get the processed URL myurl.url();//Generally, execute the jump directly location.href=myurl.url();
Debugging interface: myurl.debug(); //Modify this function for debugging
*/
function objURL(url){
var ourl=url||window.location.href;
var href="";//?Front part
var params={} ;//url parameter object
var jing="";//#and the following parts
var init=function(){
var str=ourl;
var index=str.indexOf(" #");
if(index>0){
jing=str.substr(index);
str=str.substring(0,index);
}
index=str .indexOf("?");
if(index>0){
href=str.substring(0,index);
str=str.substr(index 1);
var parts =str.split("&");
for(var i=0;i
params[kv[0]]=kv[1];
}
}else{
href=ourl;
params={};
}
};
this.set=function(key,val){
params[key]=encodeURIComponent(val);
};
this.remove=function(key){
if(key in params) params[key]=undefined;
};
this.get=function(key){
return params[key];
};
this.url=function(key){
var strurl=href;
var objps=[];
for(var k in params){
if(params[k]){
objps.push(k "=" Params [k]);
}
}
if (objps.length & gt; 0) {
strurl = "?" objps.Join ("&"); if(jing.length> Free settings
var objps=[];
for(var k in params){
objps.push(k "=" params[k]);
}
alert(objps) ;//Output all values of params
};
init();
}
Call method
JS operation URL function usage instructions:
[code]
var myurl=new objURL(); //Initialization. You can also customize the URL: var myurl=new objURL('http://www.jb51.net'');
var val=myurl.get('abc'); // Read the value of parameter abc
myurl.set("arg",data); // Add/modify the value of an arg parameter to data
myurl.remove("arg"); //Remove the arg parameter
myurl.url ();//Get the processed URL, usually jump directly: location.href=myurl.url();
myurl.debug(); //This is the debugging interface. Modify this function method for debugging

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest
