Differentiate between normal links and popup

Discussion in 'JavaScript' started by abdou_kadri, Nov 10, 2007.

  1. #1
    Hi ALL,

    Is there a way or a function that can differentiate between normal links and popup. When pressed where a warning message with only show in case normal links are pressed and won't show if the popup link are pressed

    I am using this script,

    YAHOO.namespace("example.container");
    function Warningfunction(e) {
    return confirm("ok to go?");
    }
    function init() {

    links = document.getElementsByTagName("a");
    for (var j = 0; j < links.length; j++){
    var oElementl = links.item(j);
    YAHOO.util.Event.addListener(oElementl, "click",Warnfunction);

    }

    }

    YAHOO.util.Event.onDOMReady(init);


    But this is going to grab all elements with <a> tag i.e. popup and normal links. the Warnfunction is a function that gives the Warning Message

    I'll be more than grateful for any help and suggestion ;)
     
    abdou_kadri, Nov 10, 2007 IP
  2. JeffHood

    JeffHood Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Depends on how you're calling the popup. Normal popups called with window.open can be distinguished by the following:
    YAHOO.namespace("example.container");
    function Warningfunction(e) {
    return confirm("ok to go?");
    }
    function init() {
    
    links = document.getElementsByTagName("a");
    for (var j = 0; j < links.length; j++){
    	var oElementl = links.item(j);	
    	if(oElementl.href.substr(0, 10).toLowerCase()!="javascript")
    		YAHOO.util.Event.addListener(oElementl, "click",Warnfunction);
    	}
    
    }
    
    YAHOO.util.Event.onDOMReady(init);
    HTML:
    This will add a click event to links that don't look like this:
    <a href="javasript:window.open()">anchor tag</a>
    HTML:
    Is this what you want?
     
    JeffHood, Nov 12, 2007 IP
  3. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #3
    What about links that look the way they should?
    <a href="#" onclick="window.open();return false">anchor tag</a>
    Code (markup):
     
    Logic Ali, Nov 12, 2007 IP
  4. JeffHood

    JeffHood Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    YAHOO.namespace("example.container");
    
    function Warningfunction(e){
    	return confirm("ok to go?");
    }
    
    function init() {
    	links = document.getElementsByTagName("a");
    	for (var j = 0; j < links.length; j++){
        	var oElementl = links.item(j);
    		if(!oElementl.onclick)
    			YAHOO.util.Event.addListener(oElementl, "click", Warningfunction);
    	}
    }
    
    YAHOO.util.Event.onDOMReady(init);
    HTML:
    Tested and working with the latest Yahoo libraries.
     
    JeffHood, Nov 12, 2007 IP
  5. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #5
    I think that works in the opposite sense to what was required.
     
    Logic Ali, Nov 12, 2007 IP