Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript (i)框架中的命名锚不';t跳到_Javascript_Jquery_Jsp_Firefox - Fatal编程技术网

Javascript (i)框架中的命名锚不';t跳到

Javascript (i)框架中的命名锚不';t跳到,javascript,jquery,jsp,firefox,Javascript,Jquery,Jsp,Firefox,我有一个html页面(父页面),其中包含一个iframe(这个iframe中的子页面), 这个java脚本函数获取使用内部页面链接滚动iframe的位置 function scrollToAnchor () { //function parseParameter return the query string value from the url var anchor = parseParameter(window.location.href

我有一个html页面(父页面),其中包含一个iframe(这个iframe中的子页面), 这个java脚本函数获取使用内部页面链接滚动iframe的位置

function scrollToAnchor () 
        {   //function parseParameter return the query string value from the url    
            var anchor = parseParameter(window.location.href,'anchor');

            if (anchor != null)
            {   
                location.hash=anchor;

            }
        }
but anchor value in iframe page source not in parant page,
无法滚动iframe页面。如何在parant页面中滚动iframe页面

它适用于IE和
Crome
,但不适用于
firefox
。此代码有任何替代方案。请建议。 我的parant页面url是

http://localhost:8989/schoolforms/SelectForm?formTypeID=STUDENT_EMERGENCY
这是我的
window.location.href“
值,用于iframe

http://localhost:8088/schoolforms/StudentEmergency?student=B874BCC3EA5B83670988C959E9F0036B&anchor=InsuranceInfo
解析后,此函数url变为

http://localhost:8088/schoolforms/StudentEmergency?student=B874BCC3EA5B83670988C959E9F0036B&anchor=InsuranceInfo#InsuranceInfo

JQuery bbq有一个很好的“deparam”函数


缺少的信息太多,无法理解您希望实现的具体目标。我想您需要从window.location.href的anchor变量将页面滚动到id为的anchor

我不知道函数parseParameter()是如何工作的,我需要相信它工作得很好

location.hash包含URL在#之后的部分,例如#新闻等。因此,如果您将字符串传递给location.hash浏览器会将此字符串添加到URL,并滚动到具有相同ID的html元素

效果

http://localhost:8088/schoolforms/StudentEmergency?student=B874BCC3EA5B83670988C959E9F0036B&anchor=InsuranceInfo#InsuranceInfo
这不是一个好方法,因为在这之后,URL中将同时包含锚定变量和散列

试试这个

function scrollToAnchor () 
{   
    var anchor = parseParameter(window.location.href,'anchor'); 

    if (anchor != null)
    {   
        $('html, body').animate({scrollTop: $('#'+anchor).offset().top}, 0);
    }
}
我使用了.animate(),因为如果需要,您可以将这一行中的0更改为例如默认值,即400(我猜是毫秒单位),它将随动画滚动(延迟)。如果保留0,它将立即滚动到元素,而不会有任何延迟

$('html, body').animate({scrollTop: $('#'+anchor).offset().top}, 400);

你的主播标签是什么样子啊哈,对不起,但我听到这个回答时大笑起来:D@DominicGreen和michal B。请再次阅读我的问题。如果你得到了它,因为我没有开发这个应用程序,我的理解不清楚。我只在应用程序中修复错误,所以…@london它给我的错误是:TypeError:$(…)为空[Break On This Error]$('html,body')。动画({scrollTop:$('#'+anchor).offset().top},0);@dev我忘了添加您需要加载JQuery库的内容。
嗨,Landon,我已经添加了这一点,并尝试了您的好主意,但没有在Firefox中运行。请再次阅读我的问题。如果您收到了,因为我没有开发此应用程序,我的理解不清楚。我只在应用程序中修复错误,所以……。请再次阅读我的问题如果你得到它,因为我没有开发这个应用程序,我的理解是不清楚的。我只工作在应用程序中修复错误,所以。。。。。
$('html, body').animate({scrollTop: $('#'+anchor).offset().top}, 400);