Results 1 to 3 of 3

Thread: [RESOLVED] Get a section of a URL with Javascript for use in an API Call?

  1. #1
    Join Date
    Apr 2014

    resolved [RESOLVED] Get a section of a URL with Javascript for use in an API Call?

    Hello All,

    I would like to use an API to imitate a click a link for a user in our IT Support system, i need to pass the GUID in the Javascript code. Please can anyone help with a function that can get part of a URL?

    For example i would like the GUID below that is after '&key=' but is not always the last statement (it is always 36 characters long):


    Hope there is enough information above and much appreciated for any help you can provide!

    Happy Easter!

  2. #2
    Join Date
    Mar 2005
    Behind you...
    There are a lot of functions/methods people use to get URL parameters but one that I've been using for a while now is this:
    function _URL() {
    	var $a = {};
    	var $b = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,$k,$v) { $a[$k] = $v; });
    	return $a;
    var $_GET = _URL();
    It's a simple little function that grabs all of the key/value pairs in the URL (such as 'class_name' and 'key' in your example URL). I set it equal to a variable named $_GET to emulate PHP. So if you wanted to get yoru GUID using javascript (after adding that function and variable) you would just call:
    console.log($_GET["key"]); // Outputs they GUID to the console.
    And for clarification, console.log() is only for this example. It's effectively a debug replacement for the classic alert() and is only used for this example (aka. it has nothing to do with what you'd be putting in your code). I only bring it up as it still seems to be new to many javascript developers and I wanted to avoid confusion.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Apr 2014


    Sup3rkirby, you are awesome! That did the trick and will help massively on the road to make out users lives simpler! You were correct with my lack of knowledge and experience but your instructions are fantastic.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center