Tpaul_10
asked on
A href with OnClick
Experts,
I have a link on my website like following and when I click on the link and user confirms to logout and based on my function it should logoff from
the current website and open up the new website window (which is working fine when user says yes).
The problem is, when user cancels from the alert box as per the code below, it is still opening up the new website which I don't want.
Is there anyway I can stop going/directing the user to new website when user cancels?
<a href="http://www.abcd.com/" title="Access abcd website" target="_blank" onClick="myFunction()">Cli ck Here to go to ABCD Website</a>
Thanks in advance
Appreciate your help as this is little time sensitive.
I have a link on my website like following and when I click on the link and user confirms to logout and based on my function it should logoff from
the current website and open up the new website window (which is working fine when user says yes).
The problem is, when user cancels from the alert box as per the code below, it is still opening up the new website which I don't want.
Is there anyway I can stop going/directing the user to new website when user cancels?
<a href="http://www.abcd.com/" title="Access abcd website" target="_blank" onClick="myFunction()">Cli
function myFunction()
{
if (confirm("Are you sure you want to logoff and go to ABCD website?") == true)
{
location.href = '/logoffpage.cfm?goto=loginpage';
}
else
{
return;
}
}
Thanks in advance
Appreciate your help as this is little time sensitive.
or change your href to href="#"
ASKER
Thanks for the quick response, appreciate it.
1. TechArtisan : Didn't work and still opens up the new website window.
2. dimmergeek : Didn't work either and with the # it is going to the current website when I cancels it.
if the user says yes, I need to direct the user to go to the new website and logoff from the current website (this is working fine with the current code)
and if the user says no/cancels nothing should happen. (it doesn't logoff from the current website but still going to the new website based on the current code)
Thanks
1. TechArtisan : Didn't work and still opens up the new website window.
2. dimmergeek : Didn't work either and with the # it is going to the current website when I cancels it.
if the user says yes, I need to direct the user to go to the new website and logoff from the current website (this is working fine with the current code)
and if the user says no/cancels nothing should happen. (it doesn't logoff from the current website but still going to the new website based on the current code)
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use the # in the link and remove your else clause
Yeah I noticed it didn't work after I posted it. Try this instead.
I removed the link here as well as the _blank target:
<a href="#" title="Access abcd website" onClick="myFunction()">Cli ck Here to go to ABCD Website</a>
function myFunction()
{
if (confirm("Are you sure you want to logoff and go to ABCD website?"))
{
location.href = '/logoffpage.cfm?goto=logi npage';
window.open('http://www.abcd.com/', '_blank');
}
else
{
return;
}
}
I removed the link here as well as the _blank target:
<a href="#" title="Access abcd website" onClick="myFunction()">Cli
function myFunction()
{
if (confirm("Are you sure you want to logoff and go to ABCD website?"))
{
location.href = '/logoffpage.cfm?goto=logi
window.open('http://www.abcd.com/', '_blank');
}
else
{
return;
}
}
GaryC123's suggestion works as well as my last one. Either one does what your looking for.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function myFunction()
{
if (confirm("Are you sure you want to logoff and go to ABCD website?") )
{
location.href = '/logoffpage.cfm?goto=logi
}
else
{
return;
}
}