The following code snippets work in IE and Chrome but don’t work in Firefox and I’m not sure why.
For this snippet, two links to Google appears in the webpage when opened in IE and Chrome but in Firefox nothing appears. It is located in a script tag in the body tag.
var varOne = document.createElement("a")
varOne.setAttribute("href", "http://www.google.com")
varOne.innerText = "Google"
document.body.appendChild(varOne) //attach the node to the body
var varOne = document.createElement("a")
varOne.setAttribute("href", "http://www.google.com")
varOne.textContent = "Google"
document.getElementById("bodyID").appendChild(varOne) //attach the node to the body
For this one, you click on the button to go to yahoo.com. When you press the browser’s back button, you go back to the earlier page but the javascript will run again forcing the browser to return to yahoo. Once you’ve left the original page you can’t go back and remain there without being redirected to yahoo. That’s what happens in IE and Chrome (which is what I intended just for learning purposes), but I can’t figure out why it doesn’t work in Firefox. When you come back to the original page from Yahoo, Firefox doesn’t force the browser forward like the other two browsers do.
<body>
<form>
<input type="button" onclick="javascript: window.location='http://www.yahoo.com' "/>
</form>
<script type="text/javascript">
alert("Problem?")
window.history.forward()
</script>
</body>
Try passing
1into theforwardmethod:If it doesn’t work then your probably out-of-luck as this seems to be a usability gray area between browser manufacturers. Allowing
JavaScript(something other than the user) to change the current page without his/her direct involvement is a usability issue — akin to constantly firing pop-up/pop-under windows.