Reputation: 19
I am trying to run the following JavaScript program,
function myFunction() {
var x;
if (confirm("Press a button!") == true) {
x = "You pressed Ok!";
} else {
x = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = x;
}
<p>Click the button to display a confirm box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
But I really need is not just saying "You pressed Ok" instead of that it need to open a link. Help me please.
I hope
openWindow("http://fb.com")
this line will help, but don't know where to place it and make a working program.
Upvotes: 1
Views: 1345
Reputation: 1049
function myFunction() {
var x;
if (confirm("Press a button!") == true) {
location.href = "http://www.google.com";
} else {
x = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = x;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Click the button to display a confirm box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
Upvotes: 0
Reputation: 1954
You just need to change your function and place your openWindow()
call inside it. Because I don't know what your openWindow()
function does, I would use window.open()
:
function myFunction() {
window.open("http://fb.com");
}
Upvotes: 0
Reputation: 526
if (confirm("Press a button!")) {
window.open('www.google.com')
}
Upvotes: 2