开发者

index not reset to 0 after i get back to the page by the back key

Following is the script that makes a jump menu.Using javascript i have set the index of the options tag to be equal to 0.The scrip works fine except one.After i jump to another page from the jump menu the index is not reset to the index 0.Instead it is set to the index where i had clicked.Why is it so ? What is the problem with script ?

script:

window.onload = startInit;

function startInit() {
docume开发者_StackOverflow中文版nt.getElementById("newLocation").selectedIndex = 0;
document.getElementById("newLocation").onchange = jumpPage;
}

function jumpPage() {
var newLoc = document.getElementById("newLocation");
var newPage = newLoc.options[newLoc.selectedIndex].value;
if(newPage != "")
   window.location = newPage;
}

HTML

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="script.js">
</script>
</head>

<body bgcolor="#FFFFCC">
<center>
<form>
<select id="newLocation">
 <option value="myworld.gif">first</option>
 <option value="myhome.gif">second</option>
 <option value="myroom.gif">third</option>
 <option value="mybed.jpg">fourth</option>
</select>
</form>


Browser acts smart and caches your page. So are seeing the cached version of your HTML page.To ensure that this doesn't happen and you always start up with the 0th index,tell the browser not to do anything (the way you want) when the page unloads.

The statement should be: window.onunload = function(){}; // do nothing function

you can add after window.onload = startInit;

That tells the browser that something happened during unloading and therefore it should re-read the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜