[Solved] How can you get a url for every piece of data?


<head>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdn.firebase.com/v0/firebase.js"></script>

    <script>
        var hash; // global incase needed elsewhere

        $(function() {
            hash = window.location.hash.replace("#", "");;
            myRootRef = new Firebase("http://xxxx.firebaseio.com");

            var postingRef;

            if (hash) {
                // user has been given a hashed URL from their friend, so sets firebase root to that place
                console.log(hash);

                postingRef = new Firebase("http://xxxx.firebaseio.com/chatrooms/" + hash);
            } else {
                // there is no hash, so the user is looking to share a URL for a new room
                console.log("no hash");

                postingRef = new Firebase("http://xxxx.firebaseio.com/chatrooms/");
                // push for a unique ID for the chatroom
                postingRef = postingRef.push();
                // exploit this unique ID to provide a unique ID host for you app
                window.location.hash = postingRef.toString().slice(34);
            }

            // listener
            // will pull all old messages up once bound
            postingRef.on("child_added", function(data) {
                console.log(data.val().user + ": " + data.val().message);
            });
            // later:
            postingRef.push({"message": "etc", "user": "Jimmybobjimbobjimbobjim"});
        });
    </script>

</head>

That’s working for me locally. You need to change xxxx to whatever URL yours is at, and add on however many characters that first part is at the .slice() bit.

2

solved How can you get a url for every piece of data?