简体   繁体   English

HREF链接在iPad上不起作用

[英]HREF links not working on iPad

So I've got a menu written as a nested list of the form: 所以我写了一个菜单作为表格的嵌套列表:

<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>
.
.
.

This goes on quite a while. 这持续了一段时间。 I've written some jQuery to give it a nice sliding effect. 我已经编写了一些jQuery,以使其具有不错的滑动效果。 This is in the document ready function. 这在文档准备功能中。

$('#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();
    } 
  }   
});   

Because we want people to be able to use their iPads to browse our site. 因为我们希望人们能够使用他们的iPad浏览我们的网站。 On the iPad, the sliding menu works but none of the links on the page work unless you hold down your finger over them in which case you're giving Safari's dialog box allowing you to open it/open it in a new tab/window/etc. 在iPad上,滑动菜单有效,但页面上的所有链接均无效,除非您将手指按住它们,否则会出现Safari的对话框,允许您打开/在新标签/窗口/中打开它。等等 All links, except for the sliding menu sections, require a touch hold to open them. 除滑动菜单部分外,所有链接都需要触摸才能打开。

Are you using jQuery mobile by any chance? 您是否正在使用jQuery mobile?

The first thing you learn in jQuery is to call code inside the $(document).ready() function so everything will execute as soon as the DOM is loaded. 在jQuery中学习的第一件事是调用$(document).ready()函数中的代码,以便一旦加载DOM,一切都将执行。 However, in jQuery Mobile, Ajax is used to load the contents of each page into the DOM as you navigate, and the DOM ready handler only executes for the first page. 但是,在jQuery Mobile中,Ajax用于在导航时将每个页面的内容加载到DOM中,而DOM ready处理程序仅对第一页执行。 To execute code whenever a new page is loaded and created, you can bind to the pageinit event. 要在每次加载和创建新页面时执行代码,可以绑定到pageinit事件。 This event is explained in detail at the bottom of this page. 此事件在本页底部详细说明。

if you are using a webview then you must understand that Web view contains some delegate methods to find the click event from that delegate method you need to call the URL like this 如果您使用的是Web视图,则必须了解Web视图包含一些委托方法,以便从该委托方法中查找click事件,您需要像这样调用URL

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

This is the delegate method which will fire while clicking any link inside the web view 这是在单击Web视图内的任何链接时将触发的委托方法

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

}

So there was a popup js file that had some code regarding hovering. 因此,有一个弹出js文件,其中包含一些有关悬停的代码。 There was nothing actually wrong with this code. 这段代码实际上并没有错。

The main issue here is that iPads can register click events as hovers which were competing with the touchend listener. 这里的主要问题是iPad可以将单击事件注册为悬停式事件,与触摸端侦听器竞争。

iPad/iPhone hover problem causes the user to double click a link iPad / iPhone悬停问题导致用户双击链接

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

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