homepage Welcome to WebmasterWorld Guest from 54.196.24.103
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Need to ammend a banner rotation script
So that links open in new window
litmania com




msg:605499
 12:59 am on May 18, 2001 (gmt 0)

Is this the right forum to ask Javascript questions??

How do I ammend the following banner rotation code so that the links open in a new window please? Thank you very much :)


<SCRIPT language=JAVASCRIPT type=TEXT/JAVASCRIPT>
<!-- Hide script from old browsers

adImages = new Array("http://www.qksrv.net/image-734283-1205205","/bla/ban/blabanukalig.gif","/whs/cdp/ban/cdpbanlikemusic.gif")
adURL = new Array("http://www.qksrv.net/click-734283-1205205","http://www.UKHotMovies.com/shopping","http://WHSmithMusic.cjb.net")
thisAd = 0
imgCt = adImages.length

function rotate() {
if (document.images) {
if (document.adBanner.complete) {
thisAd++
if (thisAd == imgCt) {
thisAd = 0
}
document.adBanner.src=adImages[thisAd]
}
setTimeout("rotate()", 17 * 1000)
}
}

function newLocation() {
document.location.href = "" + adURL[thisAd]
}

// End hiding script from old browsers -->
</SCRIPT>

<A href="javascript:newLocation()"><IMG

src="/bla/ban/blabanukwholepic.jpg"
name=adBanner></A></div>

 

tedster




msg:605500
 5:16 am on May 19, 2001 (gmt 0)

The following function definition is where you need to make the change.
function newLocation() {
document.location.href = "" + adURL[thisAd]
}
Instead of just resetting document.location.href, the function needs to open a new window for the URL, something like this:
function newLocation() {
window.open(adURL[thisAd],window2)
}
I'm not quite sure what those double quotes with no content are all about in the original code. Hope this gives you a place to start testing something new, anyway.
Xoc




msg:605501
 5:40 am on May 19, 2001 (gmt 0)

The double quotes could be used in other contexts to force the expression to turn into a string. If you did "6" + 7, how is that supposed to be evaluated? 13 or "67"? I don't think it has any impact in this procedure, but by concatinating a string that doesn't evaluate to a number onto something, it should cause the entire expression to become a string.

tedster




msg:605502
 11:48 pm on May 19, 2001 (gmt 0)

Good observation, Xoc. Forcing the variable to be a string makes sense. But, as you also said, it is unlikely that this is needed in this case.

Maybe this is simply a remnant of a different script that was modified for this purpose. But it sure won't hurt anything to leave that pair of double quotes in there, just to be sure.

Speaking of double quotes, I believe I forgot a pair of them -- the name of the new window, "window2", needs them. So now the code might look like this:
function newLocation() {
window.open(""+adURL[thisAd],"window2")
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved