views:

40

answers:

2

I have a page (for examle, localhost/catalog/) with select element on it.

<select name="type" id="typeSel">
    <option value="2" selected="selected" >Type 1</option>
    <option value="1"  >Type 2</option>
</select>

Also there is base tag in the page:

<base href="http://localhost/" />

I want to change page url when user click on list element. This code works in all browsers, except in Opera 10.63.

    $('#typeSel').change(function() {
        window.location.href = window.location.pathname +"?type="+$("#typeSel").val();
    });

Opera redirects browser to localhost/catalog/?type=n when there is no base tag, and and to localhost/# when base tag is used.
Could you please help me with this problem?

A: 

NEW IDEA:

Why not to access it like a DOM element?

($("head base").attr("href");

OLD IDEA: Here you have an alternative way: http://www.gotknowhow.com/articles/how-to-get-the-base-url-with-javascript

function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}
netadictos
I can't remove/change base tag because it will break the working site.
Andriy
I have added a new idea, base must be in head, or change it, and I use jquery
netadictos
A: 

I'm sorry, it was my mistake. A bug was in the other code, so I could nod reproduce it in code above in clear environment. Thank you for your help.

Andriy
You can view that bug here http://gavrylyuk.net/files/opera/
Andriy