简体   繁体   中英

How do I open a link to specific div in cordova application

I'm currently working on a mobile application using Cordova.

When I click on the 'reviews' button on one page, I want it to open up the next page (which shows more about that particular company) and automatically scroll down to the 'reviews' div on that page.

I've tried adding a scrollTop within the onclick function, adding a # to it (this breaks the link completely) and many other different things.

How can I do that? Any help would be greatly appreciated!

***Edit

a onclick="' + showpage + '"

this url is bring created from json info that is being brought in depending on certain criteria.

The page that it is on is a list of businesses, then if you click on the name, it goes to a page about that particular business. Currently when you click on the reviews, it also goes to the particular business but I want it to load the business page then automatically scroll down to the reviews div (This is being created dynamically as the page is loaded).

div class="star-review' <-- this is the div that I'm wanting it to scroll into position to.

Avoid href in a tag.... Use this simple workaround in JavaScript

    <a id="scrollToTop name="scrollToTop" value="Send">
 Scroll To Top 
</a>
     <script>  
    $("#scrollToTop").scrollTop(
$("#scrollToTop")[0].scrollHeight); 
});
  </script>

The href was being built into a function and then showpage was spitting that link out, I solved the problem by rebuilding the href without showpage and then I was able to add my #reviews to the end of it. :)

Cordova creates application using single page architecture, so it creates a link between page using hastag.

 data-role="page" id="mypage"

In your tag you need to pass data-role as page, and you need to pass its id.

When creating link on the page, you need to write link tag as mentioned below:

<a href="#mypage" data-role="button" role="button">My Page Link</a>

Thanks Amit

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