Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140331

Javascript redirect using windows.locaton.href OR windows.locaton.replace is not working. Error: window not defined

$
0
0

I have looked at all of the questions around windows.locaton.href and windows.locaton.replace not working, but still can't figure out why this redirect is not working in JavaScript. There are two JS functions I am calling when a button is clicked with submit.

<input type="submit"

onclick="NotifyUserOfNewBudgets('@Field1');redirect2MainLookup('@primaryFilename');" class="SaveChangeButton" value="Create New Budget">

The two functions are defined in Javascript as:

<script>

function NotifyUserOfNewBudgets(val) {
    alert("New Budget will be saved. NewVal=" + val);
    var ireturn;

    document.getElementById("NewBudgetID").value = val;
    document.getElementById("formMode").value = "Update";
}

function redirect2MainLookup(primaryFilename) {
    var loc = window.location.pathname;
    var host = document.location.host;
    var dir = loc.substring(0, loc.lastIndexOf('/'));

    //Replace the word Edit with blank so this redirects correctly
    var newdir = dir.replace("NewBudget", "");

    var newpath = host + newdir + primaryFilename;
    alert('newpath location = http://' + newpath);
    try {
        windows.locaton.href = "http://" + newpath;
         //window.location.replace('http://' + newpath);
    } catch (err) { alert("Error: " + err);}

}
</script>

The error I get in the try()catch() is windows is not defined and then is stays on the same page. I get the same error using windows.locaton.replace() too. I have lots of pages doing redirects, can't figure out why this one fails.


Viewing all articles
Browse latest Browse all 140331

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>