WebBrowser/Tools/Scripts.py

changeset 6692
c104c120e043
parent 6645
ad476851d7e0
--- a/WebBrowser/Tools/Scripts.py	Fri Feb 01 19:18:45 2019 +0100
+++ b/WebBrowser/Tools/Scripts.py	Fri Feb 01 20:15:03 2019 +0100
@@ -413,6 +413,29 @@
     style = css.replace("'", "\\'").replace("\n", "\\n")
     return source.format(style)
 
+
+def scrollToAnchor(anchor):
+    """
+    Function generating script to scroll to a given anchor.
+    
+    @param anchor name of the anchor to scroll to
+    @type str
+    @return script to set the style sheet
+    @rtype str
+    """
+    source = """
+(function() {{
+    var e = document.getElementById("{0}")
+    if (!e) {{
+        var els = document.querySelectorAll("[name='{0}']");
+        if (els.length)
+            e = els[0]
+    }}
+    if (e)
+        e.scrollIntoView()
+    }})()"""
+    return source.format(anchor)
+
 ###########################################################################
 ## scripts below are specific for eric
 ###########################################################################

eric ide

mercurial