PDA

View Full Version : Random Image Link



koko2589
31 Oct 2011, 1:55 AM
hi
i want
Random Image Link

inside panel
need help
like this

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"
//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.javascriptkit.com"
imagelinks[2]="http://www.netscape.com"
imagelinks[3]="http://www.microsoft.com"
imagelinks[4]="http://www.dynamicdrive.com"
imagelinks[5]="http://www.freewarejava.com"
imagelinks[6]="http://www.cnn.com"
var (http://www.cnn.com"var) ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}
random_imglink()
//-->
</script>

JambaFun
31 Oct 2011, 2:39 AM
Check out the example here:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.view.View

And you use CODE-tags.

koko2589
31 Oct 2011, 3:11 AM
Check out the example here:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.view.View

And you use CODE-tags.

tankyue
i dont want dataview
i want in panel image+link when refrech page rototor it

skirtle
31 Oct 2011, 3:42 AM
Don't rely on automatic semi-colon insertion, always put them in.

This:


var myimages=new Array()

is better written as:


var myimages = [];

Arrays have zero-based indexes. Rather than trying to fight this using 1-6, just use 0-5 instead. That way you won't need that if (ry == 0) nonsense.

You can't use document.write() to update the contents of a panel. There are a number of alternatives, update() is probably the easiest:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.panel.Panel-method-update

All in all this whole approach might be better served by an XTemplate and a single array of data objects, rather than multiple arrays.

koko2589
31 Oct 2011, 4:21 AM
Don't rely on automatic semi-colon insertion, always put them in.

This:


var myimages=new Array()

is better written as:


var myimages = [];

Arrays have zero-based indexes. Rather than trying to fight this using 1-6, just use 0-5 instead. That way you won't need that if (ry == 0) nonsense.

You can't use document.write() to update the contents of a panel. There are a number of alternatives, update() is probably the easiest:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.panel.Panel-method-update

All in all this whole approach might be better served by an XTemplate and a single array of data objects, rather than multiple arrays.

tankyou
can you give me exsample??

skirtle
31 Oct 2011, 5:26 AM
An example of which bit?

Follow my suggestions and see where it takes you...

koko2589
31 Oct 2011, 6:27 AM
i do like this its work


<script type="text/javascript">
var my_imgs = new Array();
var my_imgs_link = new Array();
var my_imgs_alt = new Array();
/* Set image URLs */
my_imgs[0] = "mako.jpg";
my_imgs[1] = "mako2.jpg";
my_imgs[2] = "mako3.jpg";
my_imgs[3] = "mako4.jpg";
my_imgs[4] = "mako5.jpg";
/* Set image link URLs */
my_imgs_link[0] = "http://www.javscriptcity.com";
my_imgs_link[1] = "http://www.pageresource.com";
my_imgs_link[2] = "http://www.pageresource.com/jscript/";
my_imgs_link[3] = "http://www.pageresource.com/html/";
my_imgs_link[4] = "http://www.javascriptcity.com/scripts/";
/ (http://www.javascriptcity.com/scripts/";/)* Set image alternate text */
my_imgs_alt[0] = "JavaScript City";
my_imgs_alt[1] = "Page Resource";
my_imgs_alt[2] = "PR JavaScript";
my_imgs_alt[3] = "PR HTML";
my_imgs_alt[4] = "JSC Scripts";
if (document.getElementById && document.createTextNode) {

var the_div = document.getElementById("my_banners");
var ran_num = Math.floor(Math.random()*(my_imgs.length));

var the_HTML = "<a href=\""+my_imgs_link[ran_num]+"\">";
the_HTML += "<img src=\""+my_imgs[ran_num]+"\" class=\"banner_imgs\" ";
the_HTML += "alt=\""+my_imgs_alt[ran_num]+"\" /></a>";
the_div.innerHTML = the_HTML;

}
</script>


html


<div id="my_banners">
<a href="http://www.default_url.com"><img src="default_image.gif"
class="banner_imgs"
/></a>
</div>


in panel
contentEl:'my_banners',

but i want is to open _blank
_blank
target _blank
i ts not good

skirtle
31 Oct 2011, 7:22 AM
var imgs = [
{
alt: 'Google',
img: 'pic1.jpg',
link: 'http://www.google.com'
}, {
alt: 'Yahoo',
img: 'pic2.jpg',
link: 'http://www.yahoo.com'
}
];

var panel = Ext.create('Ext.panel.Panel', {
height: 300,
renderTo: Ext.getBody(),
title: 'Title',
width: 300,
tpl: [
'<a href="{link}" target="_blank">',
'<img src="{img}" alt="{alt}">',
'</a>'
]
});

panel.update(imgs[Math.floor(imgs.length * Math.random())]);

koko2589
31 Oct 2011, 8:02 AM
var imgs = [
{
alt: 'Google',
img: 'pic1.jpg',
link: 'http://www.google.com'
}, {
alt: 'Yahoo',
img: 'pic2.jpg',
link: 'http://www.yahoo.com'
}
];

var panel = Ext.create('Ext.panel.Panel', {
height: 300,
renderTo: Ext.getBody(),
title: 'Title',
width: 300,
tpl: [
'<a href="{link}" target="_blank">',
'<img src="{img}" alt="{alt}">',
'</a>'
]
});

panel.update(imgs[Math.floor(imgs.length * Math.random())]);

tankyou
you are the king =D>=D>=D>=D>=D>