HTML mini browser back button disabling

走远了吗. 提交于 2019-12-13 15:58:46

问题


i have the following webpage:

<!Doctype html>
<html>
<head>
<script>
function display(value){
document.getElementById('displayer').src=value;
return false;
}
</script>
</head>
<body>
<form name="x" onsubmit="return display(this.y.value)">
<input name="y" /><input type="submit" value="display"/>
</form>
<iframe id="displayer">ERROR</iframe>
<button onclick="document.getElementById('displayer').contentWindow.history.back()">Click me to go back in the history of iframe!</button>
</body>
</html>

and the back button works fine, but when someone reaches the page they started with (in the iframe) and they click the back button it takes them to the previous page they visited in the whole browser window. how can i somehow disable the back button when someone reaches the page they started with?

i can keep track of the page they started with by using the value in the textbox, but how to know which page is currently being visited in the iframe?

if i can know which page is currently being visited in the iframe then i can easily put a conditional statement to disable the button...

i've tried:

document.getElementById("displayer").contentWindow.location.href

but it gives me undefined!

i am working on ubuntu 12.10 on google chrome latest version.

please help...


回答1:


EDIT

Answers to both questions asked:

how can i somehow disable the back button when someone reaches the page they started with?

You can't.

how to know which page is currently being visited in the iframe?

In this case, there isn't a way.

For security reasons, just like you can't fetch content with AJAX from a source outside your site, you can't get the iframe url if outside your site.



来源:https://stackoverflow.com/questions/17233849/html-mini-browser-back-button-disabling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!