Per fare questo è necessario collegare il conduttore ad un ancoraggio specifico della pagina. Per operazioni come questa è molto più facile usare un framework standard come jQuery. Per esempio, se ho avuto il seguente codice HTML
HTML:
<a id="theLink">Click Me</a>
ho potuto utilizzare il seguente jQuery per hookup un evento a questo link specifico.
// Use ready to ensure document is loaded before running javascript
$(document).ready(function() {
// The '#theLink' portion is a selector which matches a DOM element
// with the id 'theLink' and .click registers a call back for the
// element being clicked on
$('#theLink').click(function (event) {
// This stops the link from actually being followed which is the
// default action
event.preventDefault();
var answer confirm("Please click OK to continue");
if (!answer) {
window.location="http://www.continue.com"
}
});
});
grazie, se clicco cancellare anche se apre ancora il link/ – user1022585
@ user1022585 è necessario 'return false' per impedire al collegamento di spostarsi. Vedi la mia risposta qui sotto - il metodo 'Confirm' restituisce un' booleano' che puoi uscire dalla tua funzione con ... – xandercoded
scusa ho copiato il tuo codice e il tuo codice era sbagliato. se l'utente dice "ok" la risposta imposterà "true" quindi non è necessario "!", l'ho modificata. – ocanal