Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var link = document.getElementById('confirmToFollow');
- link.onclick = function () {
- return confirm("Are you sure?");
- };
- <a href="#" id="confirmToFollow"...
- var link = document.getElementById('confirmToFollow');
- link.onclick = function () {
- if( confirm("Are you sure?") ) {
- window.location = "http://www.stackoverflow.com/";
- }
- return false;
- };
- var allLinks = document.getElementsByTagName('a');
- for (var i=0; i < allLinks.length; i++) {
- allLinks[i].onclick = function () {
- return confirm("Are you sure?");
- };
- }
- <a href="mypage.html" onclick="...
- <a href="javascript: confirmLink() ...
- <a href="#" onClick="goThere(); return false;">Go to new page</a>`
- function goThere()
- {
- if( confirm("Are you sure?") )
- {
- window.location.href="newPage.aspx";
- }
- }
- <a href="http://..." onclick="return confirm('are you sure?')">text</a>
- jQuery(document).ready(
- jQuery("a").click(){
- //you'd place here your extra logic
- document.location.href = this.href;
- }
- );
- $("a").click(function() {if(confirm('yadda yadda')) event.stopPropagation();});
- $(".conf").click(function() {if(confirm('yadda yadda')) event.stopPropagation();});
- // dangerous - warnings on potentially harmful actions
- // usage: add class="dangerous" to <a>, <input> or <button>
- // Optionally add custom confirmation message to title attribute
- function dangerous_bind() {
- var lists= [
- document.getElementsByTagName('input'),
- document.getElementsByTagName('button'),
- document.getElementsByTagName('a')
- ];
- for (var listi= lists.length; listi-->0;) { var els= lists[listi];
- for (var eli= els.length; eli-->0;) { var el= els[eli];
- if (array_contains(el.className.split(' '), 'dangerous'))
- el.onclick= dangerous_click;
- }
- }
- }
- function array_contains(a, x) {
- for (var i= a.length; i-->0;)
- if (a[i]==x) return true;
- return false;
- }
- function dangerous_click() {
- return confirm(this.title || 'Are you sure?');
- }
- dangerous_bind();
- var links = document.getElementsByTagName('A');
- for (var i = 0; i < links.length; i++)
- {
- links[i].onclick = function ()
- {
- return Confirm("Are you sure?");
- }
- }
Add Comment
Please, Sign In to add comment