简体   繁体   中英

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. 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. 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. All links, except for the sliding menu sections, require a touch hold to open them.

Are you using jQuery mobile by any chance?

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. 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. To execute code whenever a new page is loaded and created, you can bind to the pageinit event. 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

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

This is the delegate method which will fire while clicking any link inside the web view

    -(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. 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/iPhone hover problem causes the user to double click a link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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