Javascript 指向div的链接工作不正常(仅限chrome)

Javascript 指向div的链接工作不正常(仅限chrome),javascript,html,google-chrome,Javascript,Html,Google Chrome,我在我的网站上有到页面上div的链接: 只有在CHROME中才会发生这种情况: 我的问题是,无论何时在初始页面加载时使用此链接(即使您只是将其粘贴到chrome浏览器中),浏览器都会向下滚动到该链接并返回到页面顶部。这让我发疯,我无法找出问题所在,(我知道我的源代码不是最漂亮的) 我在这里找不到此主题/问题,但请指向dup(如果存在) 以下是页面中的一些示例代码: <div class="row"> <div class="col-md-2"><!-- Servic

我在我的网站上有到页面上div的链接:

只有在CHROME中才会发生这种情况:
我的问题是,无论何时在初始页面加载时使用此链接(即使您只是将其粘贴到chrome浏览器中),浏览器都会向下滚动到该链接并返回到页面顶部。这让我发疯,我无法找出问题所在,(我知道我的源代码不是最漂亮的)

我在这里找不到此主题/问题,但请指向dup(如果存在)

以下是页面中的一些示例代码:

<div class="row">
<div class="col-md-2"><!-- Services side panel-->

       <nav class="navbar navbar-default hidden-lg hidden-md">
       <div class="container-fluid">
         <ul class="nav navbar-nav white">
         <li><a href="#womenshealth">Womens Health</a></li>
         <li><a href="#molec">Molecular Diagnostics</a></li>
         <li><a href="#gastro">GI / Liver</a></li>
         <li><a href="#derm">Dermatology</a></li>
         <li><a href="#hema">Hematopathology</a></li>
         <li><a href="#surg">Surgial Pathology</a></li>
         <li><a href="#urology">Genitourinary</a></li>
         <li><a href="#clinical">Clinical Lab</a></li>
         <li><a href="#hospital">Hospital Services</a></li>
         </ul>
       </div>
       </nav>

       <div class="btn-group-vertical services hidden-sm  hidden-xs" data-spy="affix"  data-offset-top="0" data-offset-bottom="300">
         <a class="btn btn-default" role="button" href="#womenshealth">Womens Health</a>
         <a class="btn btn-default" role="button" href="#molec">Molecular Diagnostics</a>
         <a class="btn btn-default" role="button" href="#gastro">GI / Liver</a>
         <a class="btn btn-default" role="button" href="#derm">Dermatology</a>
         <a class="btn btn-default" role="button" href="#hema">Hematopathology</a>
         <a class="btn btn-default" role="button" href="#surg">Surgial Pathology</a>
         <a class="btn btn-default" role="button" href="#urology">Genitourinary</a>
         <a class="btn btn-default" role="button" href="#clinical">Clinical Lab</a>
         <a class="btn btn-default" role="button" href="#hospital">Hospital Services</a>
     </div>
  </div>
<div class="col-md-10" id="srvcs" data-spy="scroll" data-target="#myNavbar"><!-- Services sections -->

<div id="womenshealth"></div>
<div class="well" >
    <div class="row">
        <div class="col-md-3"><span class="plugin_picture">

<img src="/media/cms_page_media/7/women_icon_lrg.jpg" alt="" />

</span></div>
        <div class="col-md-9"><h1 class="depth" title="Womens Health">Womens Health</h1>
<p>Quality</p><ul><li>14 experienced board certified pathologists, including 3 board certified in cytopathology</li><li>6 experienced cytotechnologists</li><li>2 experienced Clinical Genetic Molecular Biology Scientists </li></ul><p>Full Panel of GYN Testing</p><ul><li>Fully certified in ThinPrep, SurePath and Convential pap testing.</li><li><em>Chlamydia trachomatis </em>(CT) and <em>Neisseria gonorrohoeae </em>(NG) testing using Aptima Combo 2 Assay from liquid-based paps, swabs and urine.</li><li>High Risk HPV testing using the COBAS platform from liquid-based paps.</li><li>BD Affirm VPIII testing testing for <em>Candida species, Gardnerella vaginitis</em> and <em>Trichomonas vaginalis</em>.</li><li>Correlation of biopsies to pap smears.</li><li>Certified in SpiraBrush Biopsy technique for a virtually painless biopsy.</li></ul>
<div>


<p>Breast Health</p><ul><li>Onsite ER/PR and Her2 testing.</li><li>Close association with the nationally recognized Radin Breast Center.</li><li>Quick turn-around on Breast FNA's and biopsies.</li></ul><p>Fast Results</p><ul><li>Two day turn-around time on almost 95% of all paps (including ancillary testing).</li><li>Two day turn-around time for most biopsies.</li><li>24 hour turn-around time on breast FNA's.</li></ul><p>Exceptional Service</p><ul><li>Pathologists and cytotechnologists available by phone for any and all questions.</li><li>Local service means ease of adding additional testing to already received material. </li><li>In house IT to work with EMR.</li><li>In house billing to provide support for patients and insurers. </li><li>Negative pap smear results available by phone using the LabCalls service.  </li></ul></div>

<div class="panel panel-default">
  <div class="panel-body center">
    <h3>Learn more and view our resources</h3>

     <a href="/physicians/services/womens-health" class="btn btn-default">Learn more</a>
   </div>
</div>
<img src="/media/assets/images/bentedges.png" class="img-responsive up20">
</div>
    </div>
</div>
<img class="img-responsive up20 center" src="/media/images/bottom-shadow.png"/>
<div id="molec"></div>
<div class="well">
        <div class="row">
                <div class="col-md-3"><span class="plugin_picture">

<img src="/media/cms_page_media/7/dna.jpg" alt="" />

</span></div>
</div> <!--end row -->


<!-- Help Modal -->

<div class="modal fade" id="helpModal" tabindex="-1" role="dialog" aria-labelledby="helpmodal" aria-hidden="true">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times </button>
    <h4 class="modal-title" id="helpmodal">Help <span class="glyphicon glyphicon-question-sign"></span></h4>
   </div>

   <div class="modal-body">
    <p>Need help? Fill out the form below and we will reach out to you asap.</p>
    <br/>
    <iframe id="JotFormIFrame" allowtransparency="true" src="http://form.jotform.us/form/41198414446154" frameborder="0" style="width:100%; height:752px; border:none;" scrolling="no"></iframe>
    <script type="text/javascript">window.handleIFrameMessage = function(e) {var args = e.data.split(":");var iframe = document.getElementById("JotFormIFrame");if (!iframe)return;switch (args[0]) {case "scrollIntoView":iframe.scrollIntoView();break;case "setHeight":iframe.style.height = args[1] + "px";break;}};if (window.addEventListener) {window.addEventListener("message", handleIFrameMessage, false);} else if (window.attachEvent) {window.attachEvent("onmessage", handleIFrameMessage);}</script> 
   </div>

  </div>
 </div>
</div>
<!-- End Help -->

<!-- Inserts Block JS -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<Script src="/media/boots/js/bootstrap.min.js"></script>
<script src="/media/boots/js/jqBootstrapValidation.js"></script>
<!--<script src="/media/boots/js/contact_me.js"></script>-->

<script> <!-- Start Carousel -->
  $('.navbar .dropdown').hover(function() {
   $(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
  }, function() {
   $(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp()
  });
</script>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-48086237-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

女性健康 质量

  • 14名经验丰富的委员会认证病理学家,包括3名细胞病理学委员会认证
  • 6名经验丰富的细胞技术专家
  • 2名经验丰富的临床遗传分子生物学科学家
  • 全套妇科检测

    • 在ThinPrep完全认证,可靠和常规的巴氏涂片检测。
    • 使用液基巴氏涂片、拭子和尿液中的Aptima Combo 2分析进行沙眼衣原体(CT)和淋球菌(NG)检测。
    • 使用COBAS平台对液基巴氏涂片进行高危HPV检测。
    • BD确认对念珠菌进行VPIII检测,加德纳菌性阴道炎和阴道毛滴虫。
    • 活检与巴氏涂片的相关性。
    • 经SpiraBrush活检技术认证,可进行几乎无痛的活检。
      • 乳房健康

        • 现场ER/PR和Her2检测。
        • 与国家认可的Radin乳房中心密切相关。
        • 快速扭转乳房FNA和活检。
          • 快速结果

            • 几乎95%的PAP(包括辅助检测)的两天扭转时间大多数活检需要两天的周转时间。
            • 乳腺FNA需要24小时的周转时间。
              • 卓越的服务

                • 病理学家和细胞技术专家可以通过电话询问任何和所有问题。
                • 本地服务意味着可以轻松地为已收到的材料添加额外测试
                • 内部IT与EMR合作。
                • 内部计费为患者和保险公司提供支持
                • 使用LabCalls服务通过电话获得巴氏涂片阴性结果
                了解更多信息并查看我们的资源 &时代 帮助 需要帮助吗?请填写下表,我们会尽快联系您


                window.handleIFrameMessage=function(e){var args=e.data.split(“:”);var iframe=document.getElementById(“JotFormIFrame”);if(!iframe)返回;switch(args[0]){case“scrollIntoView”:iframe.scrollIntoView();break;case“setHeight”:iframe.style.height=args[1]+“px”;break;};if(window.addEventListener){window.addEventListener(“message”,handleFrameMessage,false);}else if(window.attachEvent){window.attachEvent(“onmessage”,handleFrameMessage);} $('.navbar.dropdown').hover(函数(){ $(this).find('.dropdown menu').first().stop(true,true).delay(250).slideDown(); },函数(){ $(this).find('.dropdown menu').first().stop(true,true).delay(100).slideUp() }); var _gaq=_gaq | |[]; _gaq.push([''u设置帐户','UA-48086237-1']); _gaq.push([''u trackPageview']); (功能(){ var ga=document.createElement('script');ga.type='text/javascript';ga.async=true; ga.src=('https:'==document.location.protocol?'https://ssl' : 'http://www“)+”.google analytics.com/ga.js'; var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s); })();
这可能与您嵌入的
框架
代码有关

现在,在您的页面上,它的HTML如下所示:

<iframe id="JotFormIFrame" onload="window.parent.scrollTo(0,0)" allowtransparency="true" src="http://form.jotform.us/form/41198414446154" frameborder="0" style="width: 100%; height: 692px; border: none;" scrolling="no"></iframe>

据我所知,一旦加载iframe,就会将页面滚动回顶部(无论URL中是否有id,都会发生这种情况,尽管如果没有id,那么滚动到顶部并没有任何作用)


我不知道为什么它不会在其他浏览器中做同样的事情;事件的时间可能不同,或者可能是Firefox等不允许iframe滚动父窗口。

此iframe中有一个
窗口.parent.scrollTo(0,0)
,这似乎是罪魁祸首:

<iframe frameborder="0" scrolling="no" style="width: 100%; height: 0px; border: medium none;" src="http://form.jotform.us/form/41198414446154" allowtransparency="true" onload="window.parent.scrollTo(0,0)" id="JotFormIFrame"></iframe>

不知道为什么它只在Chrome上为你做这个。。。所有浏览器都应该如此


另外,提醒您不要在问题中直接链接到您的页面。

您需要发布一些代码。而且您绝对确定没有脚本会导致滚动到顶部。抱歉,您不在办公室。页面大概有900行,不知道该发布什么。是JotForm脚本造成的,我不认为它会有任何滚动功能,但很明显它有。+1看起来你比我早4分钟到达这里。干杯还有一个
data spy=“scroll”
,我正在试验它。没问题——很高兴它有帮助!对不起,我是个笨蛋,不知道;)没必要道歉。提问是你如何获得经验的!