SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to launch pop-up from rel="external" script

    I am trying to open a pop-up window in XHTML Transitional using two scripts - one which sets rel="external" to perform the same function as the deprecated "target="_blank" and another script which sets the height/width and controls of the new window. Unfortunately, I am only an amatuer when it comes to javascript, so I've not been able to figure out why it's not working. In firefox it opens a new window, albeit full screen, and in IE it just throws an 'object expected' error. Any suggestions or pointers would be appreciated. Thanks in advance. Both scripts are below, and the html call.

    Code:
    // create new window for external links
    
    function setExternalLinks() {
    	if ( !document.getElementsByTagName ) {
    		return null;
    	}
    
    	var anchors = document.getElementsByTagName( "a" );
    	for ( var i = 0; i < anchors.length; i++ ) {
    		var anchor = anchors[i];
    		if ( anchor.getAttribute( "href" ) && anchor.getAttribute( "rel" ) == "external" ) {
    			anchor.setAttribute( "target", "_blank" )
    		}	
    			
    	 }
    	}	
    
    // pop up window parameters 
    	
    var newWin = null;
    function popUp(strURL, strType, strHeight, strWidth) {
     if (newWin != null && !newWin.closed)
       newWin.close();
     var strOptions="";
     if (strType=="console")
       strOptions="resizable,height="+
         strHeight+",width="+strWidth;
     if (strType=="fixed")
       strOptions="status,height="+
         strHeight+",width="+strWidth;
     if (strType=="elastic")
       strOptions="toolbar,menubar,scrollbars,"+
         "resizable,location,height="+
         strHeight+",width="+strWidth;
    }
    	
    function initialize() {
        setExternalLinks();
    	 popuUp();
    }
    
    window.onload = initialize;
    And the trigger in the html:

    Code:
    <a href="disclaimer.php" onclick="popUp(this.href,'console',400,200);return false;" rel="external"">Disclaimer</a>

  2. #2
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm. Actually, now Firefox isn't working at all. The javascript console is saying that popUp is not defined. I'm sure I've made an obvious mistake somewhere.

  3. #3
    SitePoint Member
    Join Date
    Oct 2004
    Location
    Colorado Springs
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just use the wndow.open with size parameters?
    Esley Ottesen
    GearHost Inc. [www.gearhost.com]
    Powerful Web Hosting for Serious Business


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •