当#在iFrame中使用HTML时,阻止页面移动

Prevent Page from Moving when # are used HTML in an iFrame

本文关键字:移动 HTML iFrame      更新时间:2023-09-26

我正在使用#links(如http://<location>/page.html#part1)的iframe中加载类似Menu的东西。每次我点击Iframe内部时,整个页面(Iframe外部)都会滚动到#所在的位置,如何防止这种情况发生?我只希望iFrame中的菜单根据需要移动。

您可以使用preventDefault() javascript函数来更改此行为。像这样的

$('#my-navigation-block a').click(function (event){ event.preventDefault(); })