/    Sign up×
Community /Pin to ProfileBookmark

Closing a popup ad

Sample link:
[I]//Moderator says: Your link has no relevance, it goes to a Flash build page//[/I]

I am currently working on a popup ad for a client and am incredibly frustrated trying to add a “close the popup” to this ad. I have found some code and augmented it to suit my clients needs but I am not very familiar with javascript and would appreciate any direction or help anyone can give.

[B]Here goes:[/B]
I am calling the javascript function in the body of the html page:

[CODE]<script language=”JavaScript1.2″>
if (iens6){
document.write(“<div id=’viewer’ style=’background-color:#762123;marginleft:0;visibility:hidden;position:absolute;width:0;height:0;z-index:1;overflow:hidden;border:0px black’></div>”)
}
if (ns4){
hideobj = eval(“document.nsviewer”)
hideobj.visibility=”hidden”
}
</script>[/CODE]

Here is the javascript:
The banner information is located inside textArray[3]

[CODE]<!– Browser Check –>
iens6=document.all||document.getElementById
ns4=document.layers
<!–GLOBAL VARIABLES–>
var thename
var theobj
var thetext
var winHeight
var winPositionFromTop
var winWidth
var startH=2
var openTimer
<!–END GLOBAL VARIABLES–>
<!–DEFINE MOUSEOVER CONTENT–>
var textArray = new Array

textArray[3]=”<a href=’http://www.hemelgroup.ca/luxury-kitchens2.asp’ target=’_blank’><img src=’http://www.hemelgroup.ca/images/BannerAd2.jpg’ border=’0′ align=’left’ width=’800′ height=’100′></a><font face=’Arial’ size=’2′><br><br><br><br><br><a href=’javascript:self.close()’>X Close</a></font><br>”

<!–END DEFINE MOUSEOVER CONTENT–>
<!–GLOBAL FUNCTIONS–>
function setObj(elementpos,theswitch,inwidth,inheight) {
thetext=textArray[3]
if(iens6){
thename = “viewer”
theobj=document.getElementById? document.getElementById(thename):document.all.thename
winHeight=100
if(iens6&&document.all) {
winPositionFromTop=document.body.clientHeight
winWidth=(document.body.clientWidth-document.body.leftMargin)
}
if(iens6&&!document.all) {
winPositionFromTop=window.innerHeight
winWidth=(window.innerWidth-(document.body.offsetLeft+20))
}
if(theswitch==”override”) {
winWidth=inwidth
winHeight=inheight
}
theobj.style.width=winWidth
theobj.style.height=startH
if(iens6&&document.all) {
theobj.style.top=document.body.scrollTop+winPositionFromTop
theobj.innerHTML = “”
theobj.insertAdjacentHTML(“BeforeEnd”,”<table cellspacing=0 width=”+winWidth+” height=”+winHeight+” border=1><tr><td width=100% valign=top><font type=’times’ size=’2′ style=’color:black;font-weight:normal’>”+thetext+”</font></td></tr></table>”)
}
if(iens6&&!document.all) {
theobj.style.top=window.pageYOffset+winPositionFromTop
theobj.innerHTML = “”
theobj.innerHTML=”<table cellspacing=0 width=”+winWidth+” height=”+winHeight+” border=1><tr><td width=100% valign=top><font type=’times’ size=’2′ style=’color:black;font-weight:normal’>”+thetext+”</font></td></tr></table>”
}
}
if(ns4){
thename = “nsviewer”
theobj = eval(“document.”+thename)
winPositionFromTop=window.innerHeight
winWidth=window.innerWidth
winHeight=100
if(theswitch==”override”) {
winWidth=inwidth
winHeight=inheight
}
theobj.moveTo(0,eval(window.pageYOffset+winPositionFromTop))
theobj.width=winWidth
theobj.clip.width=winWidth
theobj.document.write(“<table cellspacing=0 width=”+winWidth+” height=”+winHeight+” border=1><tr><td width=100% valign=top><font type=’times’ size=’2′ style=’color:black;font-weight:normal’>”+thetext+”</font></td></tr></table>”)
theobj.document.close()
}
viewIt()
}

function viewIt() {
if(startH<=winHeight) {
if(iens6) {
theobj.style.visibility=”visible”
if(iens6&&document.all) {
theobj.style.top=(document.body.scrollTop+winPositionFromTop)-startH
}
if(iens6&&!document.all) {
theobj.style.top=(window.pageYOffset+winPositionFromTop)-startH
}
theobj.style.height=startH
startH+=2
openTimer=setTimeout(“viewIt()”,10)
}
if(ns4) {
theobj.visibility = “visible”
theobj.moveTo(0,(eval(window.pageYOffset+winPositionFromTop)-startH))
theobj.height=startH
theobj.clip.height=(startH)
startH+=2
openTimer=setTimeout(“viewIt()”,10)
}
}else{
clearTimeout(openTimer)
}
}

function stopIt() {
if(iens6) {
theobj.innerHTML = “”
theobj.style.visibility=”hidden”
startH=2
}
if(ns4) {
theobj.document.write(“”)
theobj.document.close()
theobj.visibility=”hidden”
theobj.width=0
theobj.height=0
theobj.clip.width=0
theobj.clip.height=0
startH=2
}
}
onload=setTimeout(setObj,10000);
<!–END GLOBAL FUNCTIONS–>[/CODE]

I have been trying to place <a href=’javascript:self.close()’>X Close</a> in various places inside the javacode as well as the body of the page and used double quotes — “javascript:self.close()” when used outside of the textArray[3] variable.

~Days of frustration!! Please help.
Thanks
Cheshire

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 01.2007 — My first thought:

Pop-ups trend to be useless these days. Almost everybody use now pop-blockers, as the pop-up windows proved to be annoying.

Second thought:

Your code woun't work for Mozlilla.

Can you tell us which is your final aim, maybe we could find a better way?

And? What is with your link you tried to post it as a sample? That is a Flash...
Copy linkTweet thisAlerts:
@CheshireauthorOct 02.2007 — The sample link i sent is basically an embedded flash website but my client really wants [I]this[/I] type of popup ad attached to the site even against my recommendations against popup ads.

The ad is called up using javascript through the HTML page. I use Firefox, and if you wait 10 seconds, with this sample link the ad will pop up from the base of the browser window (my client wanted a delay and this type of ad considering the positioning).

My final objective is to close the ad once it comes up. My client wants a "Close this ad" link on the bottom that the user can use.

Thanks for your help!
Copy linkTweet thisAlerts:
@Orc_ScorcherOct 02.2007 — That is not a popup, it's a layer ad. I wonder what the stopIt function might do...
Copy linkTweet thisAlerts:
@CheshireauthorOct 02.2007 — Thanks Orc, I messed around with the stopit function in a few different places and finally go it to work.
×

Success!

Help @Cheshire spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...