admin管理员组

文章数量:1302274

I want to redirect to an aspx page using javascript but upon attemptin this I get the following error

uncaught type error. Property 'location'of object[object global] is not a function

How cab I redirect to a aspx page using javascript

function SearchContent() {

var txtBoxValue = $('#txtSearch').val();  
if (txtBoxValue == "") {
    alert("Please enter a value");
    return false;
}
window.location("SearchResults?search="+txtBoxValue);

I want to redirect to an aspx page using javascript but upon attemptin this I get the following error

uncaught type error. Property 'location'of object[object global] is not a function

How cab I redirect to a aspx page using javascript

function SearchContent() {

var txtBoxValue = $('#txtSearch').val();  
if (txtBoxValue == "") {
    alert("Please enter a value");
    return false;
}
window.location("SearchResults?search="+txtBoxValue);
Share Improve this question asked Jul 26, 2013 at 6:34 ArianuleArianule 9,06345 gold badges121 silver badges179 bronze badges 1
  • window.location isn't a function. See developer.mozilla/en-US/docs/Web/API/window.location for references. – Alxandr Commented Jul 26, 2013 at 6:43
Add a ment  | 

5 Answers 5

Reset to default 2

Try

location.href = "SearchResults?search="+txtBoxValue);

please try window.location.href = "SearchResults?search="+txtBoxValue;

Try This.

location.replace("SearchResults?search="+txtBoxValue);

Please check

ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('You are redirecting...');window.location='Yourpage.aspx';", true);

In Asp.NET MVC

You can also do try this:

var parameter= $("#parameter_id").val();
  1. When you want to call another action from the curent controller:

    location.href = ("actionName?parameter=" + parameter);
    
  2. When you want to call a action from another controller:

    location.windows= ("~/controllerName/actionName?parameter=" + parameter);
    

Hope it helps.

本文标签: aspnetRedirecting to an aspxpage using javascriptStack Overflow