繁体   English   中英

HREF链接在iPad上不起作用

[英]HREF links not working on iPad

所以我写了一个菜单作为表格的嵌套列表:

<ul id="nav-secondary" class="menu">
  <li><a href="javascript:;">About Us</a>
    <ul>
      <li><a href="http://our.site.com/about-us/index.php">Our History</a></li>            
      <li><a href="http://our.site.com/about-us/affiliates.php">Affiliated Stuff!</a></li>
      <li><a href="http://our.site.com/about-us/what-is-science/index.php">What is Science?</a></li>
      <li><a href="http://our.site.com/about-us/cognoscente-email-list.php">Cognoscente Email List</a></li>
      <li><a href="http://our.site.com/about-us/life-in-bloomington.php">Life In Bloomington</a></li>
      <li><a href="#">Science Links</a>                                              
        <ul>                                                                                   
          <li><a href="http://our.site.com/about-us/science-links/current-issues.php">Current Issues</a></li>
          <li><a href="http://our.site.com/about-us/science-links/experiments.php">Experiments</a></li>
          <li><a href="http://our.site.com/about-us/science-links/scientists.php">Some scientists</a></li>
          <li><a href="http://our.site.com/about-us/science-links/professional-organizations.php">Professional Organizations </a></li>
        </ul>
      </li>
      <li><a href="http://our.site.com/about-us/contact-information.php">Contact Us</a></li>      
      <li><a href="http://our.site.com/about-us/spotlights.php">Spotlights</a></li> 
      <li><a href="http://our.site.com/about-us/employment.php">Employment</a></li>        
    </ul>
  </li>
.
.
.

这持续了一段时间。 我已经编写了一些jQuery,以使其具有不错的滑动效果。 这在文档准备功能中。

$('#nav-secondary li ul').hide();
$('#nav-secondary li a').each(function () {
  var a = $(this);
  var href = $(this).attr('href'); 
  var current_page = window.location.pathname;
  if(href.indexOf(current_page) !== -1 && current_page !== "/" && current_page!== "/index.php") {
    $(this).addClass('active');
    $(this).parents().addClass('active');
    $(this).parents().show();
    $(this).attr("href", "javascript:;");
  }

});

$('#nav-secondary li > a').on('click touchstart', function() {
  if ($(this).attr('class') != 'active'){
    $(this).next().slideToggle();
    $(this).parents().addClass('active');
  } else {
    if(href.indexOf(current_page) !== -1 && current_page !== "/") {
      $(this).slideToggle();
    } 
  }   
});   

因为我们希望人们能够使用他们的iPad浏览我们的网站。 在iPad上,滑动菜单有效,但页面上的所有链接均无效,除非您将手指按住它们,否则会出现Safari的对话框,允许您打开/在新标签/窗口/中打开它。等等 除滑动菜单部分外,所有链接都需要触摸才能打开。

您是否正在使用jQuery mobile?

在jQuery中学习的第一件事是调用$(document).ready()函数中的代码,以便一旦加载DOM,一切都将执行。 但是,在jQuery Mobile中,Ajax用于在导航时将每个页面的内容加载到DOM中,而DOM ready处理程序仅对第一页执行。 要在每次加载和创建新页面时执行代码,可以绑定到pageinit事件。 此事件在本页底部详细说明。

如果您使用的是Web视图,则必须了解Web视图包含一些委托方法,以便从该委托方法中查找click事件,您需要像这样调用URL

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];

这是在单击Web视图内的任何链接时将触发的委托方法

    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
{
   [[UIApplication sharedApplication] openURL:[request URL]];
}

}

因此,有一个弹出js文件,其中包含一些有关悬停的代码。 这段代码实际上并没有错。

这里的主要问题是iPad可以将单击事件注册为悬停式事件,与触摸端侦听器竞争。

iPad / iPhone悬停问题导致用户双击链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM