`
Blackbaby
  • 浏览: 185091 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Parsing URLs with the DOM!

阅读更多
var GET = {};
var loc = String(document.location);
var pieces = loc.substr(loc.indexOf('?') + 1).split('&');
for (var i = 0; i < pieces.length; i++){
    var keyVal = pieces[i].split('=');
    GET[keyVal[0]] = decodeURIComponent(keyVal[1]);
}

 

    用法:http://blackbaby.iteye.com/admin/blogs/new?a=1&b=2,   alert(GET["a"])

   

parseURL

// This function creates a new anchor element and uses location
// properties (inherent) to get the desired URL data. Some String
// operations are used (to normalize results across browsers).
 
function parseURL(url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function(){
            var ret = {},
                seg = a.search.replace(/^\?/,'').split('&'),
                len = seg.length, i = 0, s;
            for (;i<len;i++) {
                if (!seg[i]) { continue; }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')
    };
}
分享到:
评论

相关推荐

    Parsing with Perl 6 Regexes and Grammars A Recursive Descent into Parsing epub

    Parsing with Perl 6 Regexes and Grammars A Recursive Descent into Parsing 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Human Parsing with Contextualized Convolutional Neural Network

    《Human Parsing with Contextualized Convolutional Neural Network》是2015年ICCV大会上的一篇重要论文,主要探讨了如何利用上下文信息提升人体解析的准确性。在计算机视觉领域,人体解析是一项基础任务,其目标是...

    The Theory of Parsing, Translation, and Compiling

    Aho and Ullman - The Theory of Parsing, Translation, and Compiling - Vol. 1 (1972).djvu Aho and Ullman - The Theory of Parsing, Translation, and Compiling - Vol. 2 (1973).djvu

    Drain: An Online Log Parsing Approach with Fixed Depth Tree

    本文介绍了一种在线日志解析方法,名为Drain。日志是记录系统运行时有价值信息的重要工具,在Web服务管理中被广泛使用。一个典型的基于日志分析的Web服务管理流程通常包括两个步骤:首先是解析原始日志消息,因为...

    整理的一些human parsing数据集

    数据集包括:ATR(human parsing)、LIP(Looking into Person)、Multi-human-parsing数据集。基本山涵盖了所有国际公开的human parsing数据集!

    Parsing JSON in Swift

    Parsing JSON in Swift will teach you to harness the power of Swift and give you confidence that your app can gracefully handle any JSON that comes its way. You'll learn: - How to use ...

    sdilreade(Parsing the IL of a Method Body)

    how to get a readable and programmable result from the IL array provided by the MethodBody.GetILAsByteArray() method.

    Advanced Java EE Development with WildFly(PACKT,2015)

    This book starts with an introduction to EJB 3 and how to set up the environment, including the... In the final leg of this book, we will discuss support for generating and parsing JSON with WildFly 8.1.

    OGNL关键一个类定义

    this class provides static methods for parsing and interpreting OGNL expressions!

    Java XML and JSON(Apress,2016)

    This is your one-stop guide to mastering the XML metalanguage and JSON data format along with significant Java APIs for parsing and creating XML/JSON documents (and more). The first six chapters focus...

    Trends in Parsing Technology

    - Harry Bunt, Paola Merlo, Joakim Nivre 编辑的《Trends in Parsing Technology》 - Nancy Ide, Vassar College, New York 和 Jean Véronis, Université de Provence and CNRS, France 系列编辑的《Text, Speech...

    The Busy Coders Guide to Android Development最终版2019

    Working Directly with the Camera Media Routes Supporting External Displays Google Cast and Chromecast The “Ten-Foot UI” Putting the TVs All Together: Decktastic Creating a MediaRouteProvider The ...

    Beginning XML with C# 2008: From Novice to Professional

    With this book, you’ll learn everything you need to know from the basics of reading and writing XML data to using the DOM, from LINQ and SQL Server integration to SOAP and web services. What you’...

    Script Inspector 3 v3.0.30

    Code changes are reflected instantly in its internal data structures, in the parse tree, and in the type model with symbol tables. Changes are then instantly reflected back to all your scripts… You...

    data-parsing-with-python:解析和简单的数据工作

    本主题“data-parsing-with-python:解析和简单的数据工作”将深入探讨如何利用Python进行高效的数据操作。 首先,Python中的Pandas库是数据解析的核心工具。Pandas提供了一个名为DataFrame的二维表格型数据结构,它...

    Parsing Techniques 原装扫描

    《Parsing Techniques》是一本深入探讨解析技术的权威著作,对于学习和理解编译原理的高级概念至关重要。在编程语言的设计与实现中,解析是至关重要的一步,它将源代码转换为计算机可以理解的形式。这本书详细介绍了...

    Parsing with Perl 6 Regexes and Grammars

    在计算机科学领域,解析(parsing)是一项核心技能,它涉及到如何将文本数据转换为结构化的信息,以便于程序理解和处理。Perl 6作为一种现代编程语言,不仅继承了Perl 5的强大功能,还引入了许多创新特性,使得其在...

Global site tag (gtag.js) - Google Analytics