简体   繁体   中英

Anchor tag is not working in safari iphone

Let me first add the anchor tag code

<a id="store_follow" 
    class="primary-button" 
    data-user-action='on' 
    data-id='<?php echo $value->storeId;?>' 
    data-mode='<?php echo UserUtils::ACTION_MODE_STORE_FOLLOW;?>' 
    data-toggle="true" 
    data-callback="_obs_follow_stores"
> Follow </a>

PHP is being used with this and this button works on all browser in all devices except safari in iphone.

When someone clicks on follow if user is logged in it will follow that thing and button will change to unfollow

If user is not logged in then it will open the login window popup for user.

What could be wrong with this ?

On unfollow button I am doing actions using onclick event from javascript and jquery ajax call so it's working

But in above button calling happening from PHP side.

What needs to changed to make it work on iphone safari ?

Unfollow code

<a class="primary-button active" onclick="unfollowStore('<?php echo $value->storeId;?>');"> Unfollow </a>

I can't do onclick on follow because PHP and I am just modifying this project.

Try adding the href attribute to your tag and return false from your onclick method.

<a href="#" class="primary-button active" onclick="unfollowStore('<?php echo $value->storeId;?>');return false;"> Unfollow </a>

I know you said it works in all browsers but I have seen numerous times on desktop browsers where onclick does not work in an <a> tag when it does not have an href set.

If it still doesn't work try firing a different JavaScript method. Your code might be causeing causing a JavaScript error.

To alleviate the latter make sure your unfollowStore function or any other method is wrapped in a try {} catch{} block.

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