1

I have a select like this:

<select id="Link" name="Link"><option value="">Link Websites</option>
<option value="www.google.com">test link</option>
</select>

I want to redirect to www.google.com when user select test link option. Here the js I used:

$("body").on("change", ".site > select", function () {
        if ($(this).selectedIndex != 0) {
            window.location.replace($(this).val());
        }        
    });

But instead of getting redirect to www.google.com, I got something like localhost:8000/www.google.com. Is this have anything to do with URL filter on MVC3? Or I'm missing something?

Doan Cuong
  • 2,594
  • 4
  • 22
  • 39
  • have you tried with `window.location.href()` instead of `window.location.replace()` ? have a look on this [link](http://stackoverflow.com/questions/7077770/window-location-href-and-window-open-methods-in-javascript) – Aman Gupta Jun 13 '13 at 04:58
  • use `window.location = $(this).val();` – vikas Jun 13 '13 at 04:59
  • I tried all those option, and still have the same issue – Doan Cuong Jun 13 '13 at 05:44

1 Answers1

3

You need to provide protocol in the option value for the url:

<option value="http://www.google.com">test link</option>

Otherwise it is treated as pathname (relative url) and appended to the current url.

See the documentation here

PSL
  • 123,204
  • 21
  • 253
  • 243