PDA

View Full Version : How do get URL when URL content #



tonynguyen1080
12-21-2006, 06:41 PM
Ex: Address tab http://www.myweb.com/music/index.php#Music,18

I want get full URL
http://www.myweb.com/music/index.php#Music,18

But now I only get url:
http://www.myweb.com/music/index.php

Please, help me. I want get full URL
http://www.myweb.com/music/index.php#Music,18

djr33
12-22-2006, 03:29 AM
To send a variable/value through the url, it is standard to use ?var=value, not #var,value. This is mostly used with PHP (and asp, etc, I think), but can be accessed from javascript as well.
Not sure about your current situation as I usually use php.

tonynguyen1080
12-22-2006, 09:19 PM
I'm using Ajax + PHP so url content #
At url : http://www.myweb.com/music/index.php#Music,18
I listen a song (ex: I love you). After I copy url (http://www.myweb.com/music/index.php#Music,18) and send for my friend. I want my friend listen that song (ex: I love you) too

mwinter
12-23-2006, 11:28 PM
I'm using Ajax + PHP so url content #

One does not imply the other. A fragment identifier is not appropriate based upon your description.

The fragment component identifies a secondary resource by reference to the primary resource identified by the preceding portions of the URI. In this context, a secondary resource is a portion or subset of the primary, or a particular view of it. What that means, exactly, depends on the media type of the resource.

For the familiar case of HTML, the fragment identifies a location within the document - a matching id attribute value, or some matching name attribute values[1] - and the user agent will move to that location once the document has loaded.

For other media types, the fragment component is nonsensical. It has no meaning for a PHP script as the fragment is not sent in requests and the result of server-side PHP is some other content type.



At url : http://www.myweb.com/music/index.php#Music,18
I listen a song (ex: I love you). After I copy url (http://www.myweb.com/music/index.php#Music,18) and send for my friend. I want my friend listen that song (ex: I love you) too

As djr33 suggested, use the query fragment to transfer the data. Change the format slightly to something like /music/index.php?song=18. If the PHP script is interested in this, the data can be retrieved from $_GET['song']. If client-side code is the intended user, then the information can be parsed from the document.URL property.

Mike


[1] Not all name attributes act as identifiers, such as with form controls. In that case, it is the control name used during form submission.

djr33
12-24-2006, 03:53 AM
The only advantage I can see over ? with # is that it doesn't reload the page when clicked (at least if implemented as a target/anchor setup). However, if this is the case and you are loading it live with ajax/js, then you might as well just use onclick="songname='value';" or something... no need to bother going through the URL.