locked
Can window.location.href automatic decoding be disabled when setting? RRS feed

  • Question

  • I have a search textbox where the user can search on any text they want.  To submit the request (with the value added to a querystring parameters), I am using the window.location.href in JS.  The problem is that the property seems to decode the content before redirecting the user.  For instance, if the user enters ©, IE will convert that to a copyright symbol rather than leaving the content as it.

    Is there anyway that I can disable the automatic convertion of the text string?  Other browsers like Firefox do what I would expect them to do, that is to pass the content as-is.

    Friday, October 22, 2010 8:29 PM

Answers

  • Use Form get instead.

    or

    window.location.href = 'http://search.yourwebsite.com/?=' + escape(document.getElementById('txtSearch').value);

    or

    Register at either Bing, Google or Yahoo as a Site builder and use a third party Site Search.

    Here is the link for Bing Site Search  http://www.bing.com/siteowner 

    Here is a test page for my own site  http://iecustomizer.com/MSMVP/BingSiteSearch.aspx 

    The advantage of using a Site Search service is that you don't have to do any coding or build full text search indexing in your database.

    It is a usual design pattern to use a <form> block for launching a search request. In all browsers form requests are automatically escaped.(IE browsers use the SearchHook). Unescaped location.href strings appear as errors in the w3c validators and are usually correct by validation of markup. Dynamically building a href argument does not get validated as it is computed markup.

    Regards.


    Rob^_^
    • Marked as answer by Yanping Wang Friday, October 29, 2010 10:19 AM
    Friday, October 22, 2010 8:54 PM