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?

3
  • have you tried with window.location.href() instead of window.location.replace() ? have a look on this link Commented Jun 13, 2013 at 4:58
  • use window.location = $(this).val(); Commented Jun 13, 2013 at 4:59
  • I tried all those option, and still have the same issue Commented Jun 13, 2013 at 5:44

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.