PDA

View Full Version : I need Cancel Button to be removed from java script confirm/alert box



Pat H
08-25-2015, 02:37 PM
<a href="javascript: if (confirm('Message....')) { window.open('https://www.url.com'); void('') } else { void('') }; "> <strong>Link</strong></a>

I have the code above that works well. When the user clicks on link a box opens with the message and OK and cancel button. If OK is clicked a new window opens to www.url.com but I need to get rid of the cancel button in the dialogue box. I just want the option to be OK

I've tried variations of using alert as opposed to confirm but cant seem to get it.
What am I missing?

molendijk
08-25-2015, 03:26 PM
Try this:

<a href="javascript: void(0)" onclick="alert('You will be directed to www.url.com'); window.open('http://www.url.com')"><b>Link</b></a>

Pat H
08-25-2015, 05:10 PM
Try this:

<a href="javascript: void(0)" onclick="alert('You will be directed to www.url.com'); window.open('http://www.url.com')"><b>Link</b></a>


Perfect. Thank you so much. Is there away I can mark this as Correct answer?

molendijk
08-25-2015, 05:32 PM
You can mark it as solved. (But I don't know how to do this).

Pat H
08-25-2015, 08:03 PM
You can mark it as solved. (But I don't know how to do this).

It turns out that my client wants to use jquery alert instead of javascript.
Is there anything out there that works like the onclick="alert() and window.open?

molendijk
08-25-2015, 08:31 PM
There are many jquey alerts, see http://www.sitepoint.com/10-jquery-alert-windows-prompts/
So it depends on what kind of alert your client wants.

Pat H
08-25-2015, 08:46 PM
There are many jquey alerts, see http://www.sitepoint.com/10-jquery-alert-windows-prompts/
So it depends on what kind of alert your client wants.

I guess the issues I see with these jquery alerts is after clicking OK how then do they go to the original link.
I see how it could probably work if I was going to one link every time but our links are dynamic, meaning there could be 20 different links on one page.
Also these demos I see always seem to have buttons, where I have hyperlinks that need the alert code.

molendijk
08-25-2015, 09:31 PM
You can tweak the scripts to let them do what you want. But I guess that would be a bit of a problem for you.
So as soon as I've got some time, I'll create a script for you that you could use for your custom alerts. It may take a while, 'cause I'm very busy right now.

styxlawyer
08-25-2015, 11:05 PM
<a href="javascript: if (confirm('Message....')) { window.open('https://www.url.com'); void('') } else { void('') }; "> <strong>Link</strong></a>

I have the code above that works well. When the user clicks on link a box opens with the message and OK and cancel button. If OK is clicked a new window opens to www.url.com but I need to get rid of the cancel button in the dialogue box. I just want the option to be OK

I've tried variations of using alert as opposed to confirm but cant seem to get it.
What am I missing?

I'm struggling to follow the logic here. If you are going to have only one option which is to follow the link, then why do you need the alert box? It makes more sense to just open the link directly in a new tab or window.

molendijk
08-26-2015, 08:26 PM
I'm struggling to follow the logic here. If you are going to have only one option which is to follow the link, then why do you need the alert box? It makes more sense to just open the link directly in a new tab or window.
I understand what you mean, but see the script in my next reply.

molendijk
08-26-2015, 08:29 PM
As promised, I made a script for a custom alert box that opens a new window when the user hits OK. Here (http://mesdomaines.nu/eendracht/custom_alert3/custom_alert.html) it is.