简体   繁体   中英

navigating to local anchor tag with JavaScript

I'm trying to get my Intel XDK app auto navigate to a new DIV with id="page_6" when a function fails as follow:

var fail = function(){ 
    alert("geolocation failed");
    window.location = window.location + "#page_6";
};

However, the app does NOT navigate to the new DIV.

Any ideas?

You could try using window.location.href

window.location.href = window.location + "#page_6"

Saying that, simply using window.location (as in your example code) works for me.
Are you sure that your fail callback is being executed?

Here is my working solution. Set a marker div with id to navigate to: div id="a3" /div When a condition is met [mine is in a scripted 'loop with' an int++ creating the background changes and using 'if' to evaluate when I want to navigate to div id a3] add the following script line window.location.assign("#a3");

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