简体   繁体   中英

Loading my code on the Web Archive and JavaScript not functioning correctly

I have been trying to make my code function well through multiple viewings, such as the Web Archive and through PHProxy . Here is the code :

<select id="mySelect" OnChange="window.location.href=this.value">
    <option>Tagged Stuff and Navigation</option>
</select>

<script>
    if (window.location.href.substring(0, 9) === "http://th") {
        var home_var = "/";
        var bio_var = "/tagged/bio";
        var ask_var = "/ask";
    } else if (window.location.href.substring(0, 9) === "https://p") {
        var home_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com";
        var bio_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/tagged/bio";
        var ask_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/ask";
    } else if (window.location.href.substring(0, 9) === "https://w") {
        var home_var = "blog.tumblr.com";
        var bio_var = "blog.tumblr.com/tagged/bio";
        var ask_var = "blog.tumblr.com/ask";
    }
    var select = document.getElementById("mySelect");
    var option = document.createElement("option");
    var option1 = document.createElement("option");
    var option2 = document.createElement("option");

    option.text = "Home Page";
    option.value = home_var;
    select.add(option);

    option1.text = "Autobiographys";
    option1.value = bio_var;
    select.add(option1);

    option2.text = "Ask Me Stuff";
    option2.value = ask_var;
    select.add(option2);
</script>

My specific problem is when opening my page through the Web Archive the variables never properly get defined so all of the values come out as "undefined". Is this a problem with the Web Archive, or is there anyway I can get around the problem?

window.location.href.substring(0,9) does not contain the matched string. The condition was not mached and the default value also not defined because of this reason the value come out as undefined.

check with

console.log(window.location.href.substring(0, 9));

this is what i've tried

<select id="mySelect" OnChange="window.location.href=this.value">
    <option>Tagged Stuff and Navigation</option>
</select>

<script>
    var home_var = "";
    var bio_var = "";
    var ask_var = "";
    // Check your variable
    console.log(window.location.href.substring(0, 9));
    if (window.location.href.substring(0, 9) === "http://th") {
        home_var = "/";
        bio_var = "/tagged/bio";
        ask_var = "/ask";
    } else if (window.location.href.substring(0, 9) === "https://p") {
        home_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com";
        bio_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/tagged/bio";
        ask_var = "https://px.multiscreensite.com/index.php?url=blog.tumblr.com/ask";
    } else if (window.location.href.substring(0, 9) === "https://w") {
        home_var = "blog.tumblr.com";
        bio_var = "blog.tumblr.com/tagged/bio";
        ask_var = "blog.tumblr.com/ask";
    } else {
        //Set Default Values
        home_var = "default home var";
        bio_var = "default home var";
        ask_var = "default home var";
    }
    var select = document.getElementById("mySelect");
    var option = document.createElement("option");
    var option1 = document.createElement("option");
    var option2 = document.createElement("option");

    option.text = "Home Page";
    option.value = home_var;
    select.add(option);

    option1.text = "Autobiographys";
    option1.value = bio_var;
    select.add(option1);

    option2.text = "Ask Me Stuff";
    option2.value = ask_var;
    select.add(option2);
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM