Chrome / binding operator shifts after adding dom elements

Let's say I have a URL: http://rythmengine.org/doc/expression.md#transformer

Immediately after loading the page, the anchor is displayed correctly, however I have a script to automatically add some iframes on the page, chrome / opera will later be displaced from the anchor #comment , firefox and IE (10) all is well.

Any idea how to fix this in Chrome / opera?

+4
source share
2 answers

When each iframe download finishes, tell the browser to go to that hash

 $('iframe').load(function() { document.location.href = document.location.hash; }); 
+1
source

I don’t know whether I will implement it or not, since the frames take a noticeable amount of time to load, and the user can already scroll the page and return to the hash element, but here I decided to use jQuery.

Since frames are replaced in the document after the initial load, you can use the .load() function, which usually never works if you just use it in the document.

Demo on this page and change the violin here .

Just add this jQuery code to the script tag, where you replace all the pre code :

Code:

 $('iframe').load(function() { moveToHash(); }); // Scroll to the url hash element function moveToHash() { var hashElem = $(window.location.hash); // If the hash elment exists if(hashElem.length) { window.scrollTo(hashElem.position().left, hashElem.position().top); } } 

Edit: There were several bugs and unnecessary in the code that are now fixed.

+3
source

All Articles