Probar varias combinaciones de configuración de la ubicación del marco o el hash todavía desafortunadamente resultó en el desplazamiento principal.
Así que esto es lo que terminé haciendo ya que el contenido del iframe estaba en el mismo dominio, por lo que no había un problema entre sitios navegando por el marco DOM.
Modifiqué los enlaces en el elemento primario así que en lugar de hacer target="myiframe"
, agregué una función en punto para hacer el desplazamiento omitiendo la implementación predeterminada (que parece hacer que el padre salte al iframe).
función
<a onclick="linkFunction(this, event);return false;"...
El enlace es el siguiente:
/// for scrolling iframe without jumping parent page
function linkFunction(atag, event) {
event.preventDefault();
var iframe = document.getElementById('myiframe');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var name = atag.href.split('#')[1]; // get the hash
var anchor = innerDoc.getElementsByName(name)[0]; // find the corresponding anchor tag
// get position of the anchor relative to the current scroll position
var offset = anchor.getBoundingClientRect().top
// jump scroll the iframe content to the anchor
iframe.contentWindow.scrollBy(0, offset)
}
Sin jQuery y todavía funciona correctamente si JavaScript desactivado (solo vuelve a saltar la matriz por defecto).
Espero que esto ayude a alguien más.
verificado en Chromium 17 –
Tengo el mismo problema. Chrome y FF probado. –