Results 1 to 6 of 6

Thread: FrogJS - open linke in a new window

  1. #1
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default FrogJS - open linke in a new window

    1) Script Title: FrogJS Image Gallery

    2) Script URL (on DD):

    http://dynamicdrive.com/dynamicindex4/frogjs/index.htm

    3) Describe problem:

    How can I make the links open in a new window, when clicking on the image?

    Thanks!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In frog.js find this near the beginning, and add the red part:

    Code:
    		// Builds imageArray of all images, thumbnails, credits, and captions
    		var anchors = $('FrogJS').getElementsByTagName('a');
    		for (var i=0; i<anchors.length; i++){
    			imageArray[i] = new Array();
    			imageArray[i]['full'] = anchors[i].getAttribute('href');
    			imageArray[i]['credit'] = anchors[i].getAttribute('title');
    			imageArray[i]['thumb'] = anchors[i].getElementsByTagName('img')[0].getAttribute('src');
    			imageArray[i]['caption'] = anchors[i].getElementsByTagName('img')[0].getAttribute('alt');
    			imageArray[i]['link'] = anchors[i].getAttribute('rel');
    			imageArray[i]['target'] = anchors[i].getAttribute('rev');
    		}
    Next, find this section nearer to the bottom (starting around line #157):

    Code:
    	// loadMainImage()
    	// Fades out old main image and fades in new one.  Also updates credit and caption
    	loadMainImage: function(imageNum, width){
    		Element.setCursor('FrogJSImage','');
    		$('FrogJSImage').onclick = function(){};
    		new Effect.Fade('FrogJSMainContainer', { duration:0.5, afterFinish: function(){ showMainImage(); } });
    		function showMainImage(){
    			$('FrogJSImage').style.display = 'block';
    			$('FrogJSImage').src = imageArray[imageNum]['full'];
    			$('FrogJSMainContainer').style.width = width+'px';
    			$('FrogJSCredit').innerHTML = imageArray[imageNum]['credit'];
    			$('FrogJSCaption').innerHTML = imageArray[imageNum]['caption'];
    			new Effect.Appear('FrogJSMainContainer', { duration: 0.5, afterFinish: function(){ addOnclick(); } });
    			function addOnclick(){
    				if(imageArray[imageNum]['link']){
    					Element.setCursor('FrogJSImage','pointer');
    					$('FrogJSImage').onclick = function(){
    						location.href = imageArray[imageNum]['link'];
    					}
    				}
    			}
    		}
    	},
    Replace it with (change highlighted red):

    Code:
    	// loadMainImage()
    	// Fades out old main image and fades in new one.  Also updates credit and caption
    	loadMainImage: function(imageNum, width){
    		Element.setCursor('FrogJSImage','');
    		$('FrogJSImage').onclick = function(){};
    		new Effect.Fade('FrogJSMainContainer', { duration:0.5, afterFinish: function(){ showMainImage(); } });
    		function showMainImage(){
    			$('FrogJSImage').style.display = 'block';
    			$('FrogJSImage').src = imageArray[imageNum]['full'];
    			$('FrogJSMainContainer').style.width = width+'px';
    			$('FrogJSCredit').innerHTML = imageArray[imageNum]['credit'];
    			$('FrogJSCaption').innerHTML = imageArray[imageNum]['caption'];
    			new Effect.Appear('FrogJSMainContainer', { duration: 0.5, afterFinish: function(){ addOnclick(); } });
    			function addOnclick(){
    				if(imageArray[imageNum]['link']){
    					Element.setCursor('FrogJSImage','pointer');
    					$('FrogJSImage').onclick = function(){
    						window.open(imageArray[imageNum]['link'],imageArray[imageNum]['target']||'_self');
    					}
    				}
    			}
    		}
    	},
    Once you have done that, the script will behave exactly as it always did, unless you specify a rev attribute in the link, ex:

    Code:
    <a href="images/1.jpg" title="Google" rel="http://www.google.com/" rev="_new"> . . .
    If you do that, you will get a new window. You can also use this rev attribute to target a named frame, named iframe, or named existing window.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much for the time an work.

    Thank you for replying first and fast.

    Thanks!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I played around with this a bit more, thinking it would be neat to be able to open a customized new window. I worked out a method whereby that could be done. I made the first change look like so:

    Code:
    		// Builds imageArray of all images, thumbnails, credits, and captions
    		var anchors = $('FrogJS').getElementsByTagName('a');
    		for (var i=0; i<anchors.length; i++){
    			imageArray[i] = new Array();
    			imageArray[i]['full'] = anchors[i].getAttribute('href');
    			imageArray[i]['credit'] = anchors[i].getAttribute('title');
    			imageArray[i]['thumb'] = anchors[i].getElementsByTagName('img')[0].getAttribute('src');
    			imageArray[i]['caption'] = anchors[i].getElementsByTagName('img')[0].getAttribute('alt');
    			imageArray[i]['link'] = anchors[i].getAttribute('rel')?anchors[i].getAttribute('rel').split('::')[0]:null;
    			imageArray[i]['target'] = anchors[i].getAttribute('rel')?anchors[i].getAttribute('rel').split('::')[1]:null;
    			imageArray[i]['specs'] = anchors[i].getAttribute('rev');
    		}
    and the second one:

    Code:
    	// loadMainImage()
    	// Fades out old main image and fades in new one.  Also updates credit and caption
    	loadMainImage: function(imageNum, width){
    		Element.setCursor('FrogJSImage','');
    		$('FrogJSImage').onclick = function(){};
    		new Effect.Fade('FrogJSMainContainer', { duration:0.5, afterFinish: function(){ showMainImage(); } });
    		function showMainImage(){
    			$('FrogJSImage').style.display = 'block';
    			$('FrogJSImage').src = imageArray[imageNum]['full'];
    			$('FrogJSMainContainer').style.width = width+'px';
    			$('FrogJSCredit').innerHTML = imageArray[imageNum]['credit'];
    			$('FrogJSCaption').innerHTML = imageArray[imageNum]['caption'];
    			new Effect.Appear('FrogJSMainContainer', { duration: 0.5, afterFinish: function(){ addOnclick(); } });
    			function addOnclick(){
    				if(imageArray[imageNum]['link']){
    					Element.setCursor('FrogJSImage','pointer');
    					$('FrogJSImage').onclick = function(){
    						window.open(imageArray[imageNum]['link'],imageArray[imageNum]['target']||'_self',imageArray[imageNum]['specs']||'');
    					}
    				}
    			}
    		}
    	},
    This allowed for normal operation as before, but now the target (if used) would be added to the rel attribute, like so using :: as a separator:

    Code:
    <a href="images/1.jpg" title="Google" rel="http://www.google.com/::_blank"> . . .
    Just that much would get you a new window (target="_blank"), and if you wanted to add custom specifications, that's what I now used the rev attribute for:

    Code:
    <a href="images/1.jpg" title="Google" rel="http://www.google.com/::_blank" rev="width=550, height=330, scrollbars"> . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Aug 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks again!

  6. #6
    Join Date
    Jan 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i had the same problem; ty johnny

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
  •