I am looking to have the user be page jumped to an already anchored part of my site depending on their choice in the alert box. When the alert box pops up, if they confirm that they have an iPhone (it is just informational, the device truly doesnt matter) it should say "Cool" and leave them where they are because the iPhone information starts at the top. However if they cancel I want them to be page jumped down to the bottom of the page where the Android information begins.

I have been browsing stack overflow and other various sites but I cannot find something that addresses this, but excuse me if I am wrong.

<!--the Javascript function -->

function Question() {
var x=window.confirm("You have an iPhone right???")
if (x)
window.alert("Good!")
else
window.alert("Here is info for your device type!")
}

<!-- the html im looking to jump to -->

<h2 id = galaxyInt><a id = "SamsungStart">Samsung Galaxy Mobile 
Security</a></h2>

I am hoping through not clicking the alert box confirmation that the else statement will jump the user down the page to the proper section.

1 Answers

0
Jonny On Best Solutions

Use window.location.href = "#SamsungStart"; to link to the id you want to go to.

<!--the Javascript function -->

function Question() {
var x=window.confirm("You have an iPhone right???")
if (x)
window.alert("Good!")
else
window.location.href = "#SamsungStart";
}
Question();
#top{
width:100%;
height:300px;
float:left;
background-color:blue;
}
.container2{
width:100%;
height:400px;
float:left;
background-color:green;

}
#galaxyInt{
width:100%;
float:left;

}
#SamsungStart{
width:100%;
float:left;
}
<!-- the html im looking to jump to -->

<div id = "top"></div>



<div class="container2">
<h2 id = "galaxyInt"><a id = "SamsungStart">Samsung Galaxy Mobile 
Security</a></h2></div>