UXdesigner
UXdesigner

Reputation: 823

Help fixing a Javascript redirect issue

I have this javascript that takes me to the spanish version of the web page. But if the URL is www.domain.com/ with NO filename.aspx (like index or default.aspx) it wont take me to the spanish site.

// Index - Inicio 
if (url.indexOf("inicio") > 0)
  newURL = url.replace("~/es/inicio.aspx", "~/index.aspx");
    else 
  newURL = url.replace("~/index.aspx", "~/es/inicio.aspx");

then if I create another javascript like this, it wouldn't do it, it would just add the page to the url, after the first url ...

if (url.indexOf("inicio") > 0)
  newURL = url.replace("~/es/inicio.aspx", "/");
    else 
  newURL = url.replace("/", "~/es/inicio.aspx");

How can I fix that ?

If I hit ESPANOL, it wouldn't take me to the /es/inicio.aspx page. because the URL when I load the page at first doesn't have an index.aspx it's just the domain

SOLUTION Fixed this situation as follows: Created a default.aspx and set the priority first in the IIS document management. And default.aspx had this script inside. That did it for me and the javascript inside of the website works wonders now. The URL is always URL/index.aspx

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Redirect("~/index.aspx", false);     
    }

</script>

Upvotes: 0

Views: 170

Answers (2)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

First of all Tild Sign is not supported in JavaScript URL redirection.

Secondlly why not use the Window.Location = "URL"; ?

Upvotes: 1

Pointy
Pointy

Reputation: 413702

Your call to "replace()" here:

  newURL = url.replace("/", "~/es/inicio.aspx");

says to replace the first "/" character in the URL with that replacement string. If the URL contains more characters than just a slash (which seems likely), then they'll remain after the replacement. We don't know what your overall URL scheme is, but if you want to simply replace the original URL, you'd just do this:

  newURL = "~/es/inicio.aspx";

and dispense with "replace()" altogether.

Upvotes: 0

Related Questions