getting the page URL

Share your advanced knowledge/code with the community.
novaseer
Posts: 5
Joined: Wed Feb 26, 2014 1:34 am

getting the page URL

Post by novaseer »

Code: Select all

Procedure.s getURL()
  !return window.location.host;
EndProcedure

Procedure.s getURLpath()
  !return window.location.pathname;
EndProcedure

Procedure.s getURLparam()
  !return window.location.search;
EndProcedure
if the URL is 'http://www.somesite.com/path/subpath/page.html?parameter1+parameter2', each procedure will give the following:

getURL... www.somesite.com
getURLpath... /path/subpath/page.html
getURLparam... ?parameter1+parameter2
User avatar
eddy
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

Re: getting the page URL

Post by eddy »

Hi,
I updated your last function:

Code: Select all

Procedure.s getURLparam(ParamName.s="")
  If ParamName    
    !var results = new RegExp('[\\?&]' + v_ParamName + '=([^&#]*)').exec(window.location.search);
    !return (results==null) ? null : decodeURIComponent(results[1]) || 0;
  Else 
    !return window.location.search;
  EndIf 
EndProcedure
if the URL is 'http://www.somesite.com/path/subpath/pa ... e&arg3=200'
getURLparam("arg3") will return "200"
getURLparam("arg2") will return "true"
getURLparam("arg1") will return "HELLO WORLD"
getURLparam() will return ?arg1=HELLO%20WORLD&arg2=true&arg3=200
novaseer
Posts: 5
Joined: Wed Feb 26, 2014 1:34 am

Re: getting the page URL

Post by novaseer »

nice
Post Reply