I'm using an iframe
, and I have a back button which runs this javascript code (when user clicks on back button):
document.getElementById("myframe").contentWindow.history.go(-1); // back
This works fine, but If there is no previous page in the frame, main page will go back.
How to avoid this? I want just iframe to go back, and if there is no previous page, simply do nothing.
EDIT: This is my code. (@ jsfiddle)
I'm using an iframe
, and I have a back button which runs this javascript code (when user clicks on back button):
document.getElementById("myframe").contentWindow.history.go(-1); // back
This works fine, but If there is no previous page in the frame, main page will go back.
How to avoid this? I want just iframe to go back, and if there is no previous page, simply do nothing.
EDIT: This is my code. (@ jsfiddle)
Share Improve this question edited Jul 22, 2012 at 17:36 Mahdi Ghiasi asked Jul 22, 2012 at 17:17 Mahdi GhiasiMahdi Ghiasi 15.3k19 gold badges77 silver badges121 bronze badges 5- Maybe check iframes 'location.href' property? If it's default - do nothing. – sleepwalker Commented Jul 22, 2012 at 17:37
- @sleepwalker I haven't tested it, it seems to work fine. But... Isn't there any better way?? – Mahdi Ghiasi Commented Jul 22, 2012 at 17:42
-
I'm not using plete address. (I'm using
../myfolder/a.html
), and even checkingiframe.src
didn't work. – Mahdi Ghiasi Commented Jul 22, 2012 at 17:45 -
What do you mean about checking
location.href
?? what islocation.href
? – Mahdi Ghiasi Commented Jul 22, 2012 at 17:45 - document.getElementById('myframe').contentWindow.location.href It will work only if you are on the same domain. – sleepwalker Commented Jul 22, 2012 at 18:20
1 Answer
Reset to default 3Keep track of changes like this:
<script>
window.iFrameChanges = -1; //will get incremented to 0 on first page load
</script>
<iframe onLoad="window.iFrameChanges+=1;" src="..."></iframe>
And the decrement the window.iFrameChanges
value on history go back
This way you can know the "length" of history
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745302063a4621492.html
评论列表(0条)