JS - URL parsing to extract a particular parameter value

Posted on 2010-01-12
Medium Priority
Last Modified: 2013-11-08
I'm familiar in PHP, but not JS -
i have a page where its URL would end in the form:

I need to extract the value for the $_GET['p']   variable.
Is this possible to do in JS?

the reason i need it in JS  is because it's in the header, ahead of the execution of PHP-generated  content.

Question by:willsherwood
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 82

Expert Comment

ID: 26298456
Hello willsherwood,

Check the gup function here : http://www.netlobo.com/url_query_string_javascript.html

LVL 82

Accepted Solution

leakim971 earned 2000 total points
ID: 26298561
Work too :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function displayP() {
		var url = "http://www.google.php?p=456&jp=j&n=Ac";
		alert( url.substring( url.indexOf("?")+2 ,url.indexOf("&", url.indexOf("?")+2) ) );
<body onload="displayP();">

Open in new window


Author Closing Comment

ID: 31676386
thank you!!!
LVL 82

Expert Comment

ID: 26298583
You're welcome! Thanks for the points!

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Fine Tune your automatic Updates for Ubuntu / Debian
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question