Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why window.location appending instead of replacing the URL in ie

I am getting wrong URLs in ie but not in firefox and chrome.

Basically, I have a textfield called text-search. I am using jQuery and rewriterule in htaccess to internally redirect pages. I am on localhost and all files are in a folder called test.

In firefox and chrome, if you enter 'hello' hit enter, 'hi' hit enter and 'goodbye' hit enter in the text-search box you get the correct URLs as

localhost/test/testing/hello

and

localhost/test/testing/hi

and

localhost/test/testing/goodbye

repectively.

In ie you get

localhost/test/testing/hello

and

localhost/test/testing/testing/hi

and

localhost/test/testing/testing/testing/goodbye

respectively

The problem here is that 'testing' is prepending. How to stop this from happening in ie. I could not find an answer to this problem on the web.

html and jquery code

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>


        <base href="http://localhost/test/" />
        <script src="jQuery.js"></script>
        <script>
            $(document).ready(function(){
                $("#text-search").keyup(function(e){
                    if (e.keyCode == 13){
                        window.location.replace("testing/"+$('#text-search').val());
                    }
                })
            })
        </script>
    </head>

    <body>
        <input type='text' id='text-search'>
    </body>
</html>

.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^testing/(.+)$ /test/testing.php?string=$1 [L]

Can you please help me on this. Many thanks

like image 250
Hani Avatar asked Oct 04 '13 16:10

Hani


People also ask

What does Window location replace do?

Window location. The replace() method replaces the current document with a new one.

What is window location assign?

The Location. assign() method causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.

How do I find my Windows location URL?

Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.

What is window location href?

Window Location Href The window.location.href property returns the URL of the current page.


1 Answers

If you set like this: window.location.href = '/yourpage'

it will append the url. To avoid that use // instead of /

so it will look like :window.location.href = '//yourpage'

like image 120
Charitha Goonewardena Avatar answered Sep 22 '22 04:09

Charitha Goonewardena