Results 1 to 3 of 3

Thread: js GET function

  1. #1
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Exclamation js GET function

    Hello,

    I have php file and Im editing the content via url and get function.

    /webmaster/out.php?Entry=11&width=236&margin=2.8&bgColor=fff&titleColor=AB277D&borderColor=cccccc
    <?php echo $_GET['id'];?> << I use that inside the php file


    What is the js version of that function?

    thank you in advance!

  2. #2
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Users can put my contents thru iframe but I want to use a js version instead... been searching for 3 hrs and still get no solution...

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Nothing standard for that. This works:

    Code:
    function getQval(n) {
    	if(typeof n !== 'string'){
    		return null;
    	}
    	var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
    	return (m = r.exec(m))? unescape(m[1]) : null;
    }
    With that in hand (already available to the page), you can replace:

    PHP Code:
    <?php echo $_GET['id'];?>
    with:

    Code:
    <script type="text/javascript">document.write(getQval('id'));</script>
    There are of course various other ways to use it. And it will now only work if the client has javascript enabled, so best to keep some form of the PHP version as a fall back. How you implement either/both depends a lot upon what exactly you are trying to do.
    Last edited by jscheuer1; 02-12-2011 at 03:02 PM. Reason: add bit about fall back, depends
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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