
Originally Posted by
ldoozer
Any ideas why this doesnt work?
Nothing definitive without seeing an example. There might be an error elsewhere that prevents execution of the code. The body element might have an onload attribute. Please post a link to a demonstration. It doesn't have to be the document you're working on, just an example of what you're trying to do and the code you're trying to use to do it.
In the meantime:
<script language="JavaScript">
The language attribute has been deprecated for a long time. Use the type attribute:
HTML Code:
<script type="text/javascript">
This variable isn't used, at least in the code you posted. You should consider removing it.
if (document.cookie.indexOf("isloaded")==-1){
Before using that the cookie property, you should check to make sure it exists, is a string, and actually behaves as a dynamic property. If cookies are disabled, none of these things may be true, and your code will raise an exception.
Whilst on the subject, have you considered the impact that your scheme will have on users with cookies disabled? Will it be very intrusive if every time they return, this pop-up of yours will be shown?
document.getElementById("whyWeAsk").className == 'popperHid' ? document.getElementById("whyWeAsk").className = 'popperShow' : document.getElementById("whyWeAsk").className = 'popperHid';
Yikes! What on Earth is that? You seem to have confused when to use a conditional statement, and the conditional operator (?:). Either use:
Code:
/* Check for support of the getElementById method before using it. */
if (document.getElementById) {
/* Save a reference to the element; there's no need to obtain it multiple times. */
var popUp = document.getElementById("whyWeAsk");
if (popUp)
if (popUp.className == "popperHid") popUp.className = "popperShow";
else popUp.className = "popperHid";
}
or:
Code:
if (document.getElementById) {
var popUp = document.getElementById("whyWeAsk");
if (popUp) popUp.className = (popUp.className == "popperHid")
? "popperShow" : "popperHid";
}
The conditional operator should only be used within expressions, just like any other operator. It is not a substitute for an if statement.
Surely that's a mistake?
document.cookie="isloaded=1"
This won't ever be executed due to the return statement above, but even if it was, are you aware that it will only create a session cookie? The next time the user loads their browser and returns to your site, the cookie will have expired and the pop-up will appear again. Is that your intention?
Mike
Bookmarks