Callum Whyte
Callum Whyte

Reputation: 2429

Adding title to page with instant jQuery search script

I have a Google Instant style search script written in jQuery. When the user queries, #SEARCHTERM is added onto my page URL. I was wondering how I could add the users query into the title of my page so it would be "SEARCHTERM - My Search Script"

Here is my current code:

$(document).ready(function(){
    $("#search").keyup(function(){
        var search=$(this).val();
        var keyword=encodeURIComponent(search);
        var yt_url='search.php?q='+keyword+'&category=web';
        window.location.hash=keyword;

        $.ajax({
            type:"GET",
            url:yt_url,
            dataType:"html",
            success:function(response){
                $("#result").html(response);
            }
        });
    });
});

Upvotes: 1

Views: 191

Answers (1)

Niklas
Niklas

Reputation: 30002

Assign title with: document.title

document.title = $(this).val() + " - My Search Script";

Upvotes: 1

Related Questions