Forum Moderators: open

Message Too Old, No Replies

External script doesn't work like it did in the body tag.

         

JAB Creations

8:22 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the external script I have now.

var clickCount=0;
document.onClick='clickCount++';
if(clickCount==4){parent.border.location='htt:/ww.e_x_a_m_p.com/home/home-border-top-pissed1.php'};
if(clickCount==8){parent.border.location='htt:/ww.e_x_a_m_p.com/home/home-border-top-pissed2.php'};
if(clickCount==12){parent.border.location='htt:/ww.e_x_a_m_p.com/home/home-border-top-pissed3.php'};
if(clickCount==16){parent.border.location='htt:/ww.e_x_a_m_p.com/home/home-border-top-pissed4.php'};
if(clickCount==20){parent.border.location='htt:/ww.e_x_a_m_p.com/home/home-border-top-pissed5.php'};
if(clickCount==22){clickCount=0}

Here is how the code worked fine...


<script type="text/javascript">
<!--
var clickCount=0;
//-->
</script>
</head>
<body onClick="clickCount++;if(clickCount==4){parent.border.location='htt:/ww.e_x_a_m_p .com/home/home-border-top-pissed1.php'};if(clickCount==8){parent.border.location='htt:/ww.e_x_a_m_p .com/home/home-border-top-pissed2.php'};if(clickCount==12){parent.border.location='htt:/ww.e_x_a_m_p .com/home/home-border-top-pissed3.php'};if(clickCount==16){parent.border.location='htt:/ww.e_x_a_m_p .com/home/home-border-top-pissed4.php'};if(clickCount==20){parent.border.location='htt:/ww.e_x_a_m_p .com/home/home-border-top-pissed5.php'};if(clickCount==22){clickCount=0}">

Bernard Marx

11:32 am on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript is case sensitive. HTML event handlers aren't.
Javascript event handlers aren't interCapped.

document.on[b]c[/b]lick='clickCount++';

JAB Creations

7:42 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No ... I think you've mispercieved my issue. I'm trying to get the script to work externally so I can just include it in the head of each file.

The problem is I can't get it to work as an external script.

Also email notification of replies isn't working?

Bernard Marx

9:34 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry J, wasn't looking closely enough.
What I said is true (onClick: bad onclick: good), but there's more

document.onClick='clickCount++';

You need to assign a function to the event.
Right know, you are just assigning a string : "clickCount++"
(( to a custom property, onClick ))

[pre]document.onclick=function()
{
clickCount++
if(clickCount ..etc)
...etc
};[/pre]

Also email notification of replies isn't working

I try my hardest to please, but I can't solve everything :)

Bernard Marx

10:37 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I had a go at an alternative version.
Any good to you?


var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;

document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location
='htt:/ww.e_x_a_m_p.com/home/home-border-top-pissed'
+(clickCount/ clickSpacing)+'.php';
}

JAB Creations

5:03 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I tried your first attempt ...

document.onclick=function()
{
clickCount++
if(clickCount==4){parent.border.location='http://www.?.com/home/home-border-top-pissed1.php'};
if(clickCount==8){parent.border.location='http://www.?.com/home/home-border-top-pissed2.php'};
if(clickCount==12){parent.border.location='http://www.?.com/home/home-border-top-pissed3.php'};
if(clickCount==16){parent.border.location='http://www.?.com/home/home-border-top-pissed4.php'};
if(clickCount==20){parent.border.location='http://www.?.com/home/home-border-top-pissed5.php'};
if(clickCount==22){clickCount=0}

... and it didn't work.

The second script only allows me to specify one url? So I tried modding it as so. Also how do I set the number for each click count to trigger? Whats % do?

var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;

document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location ='http://www.?.com/home/home-border-top-pissed1.php' +(clickCount/ clickSpacing)+'.php';

else(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location ='http://www.?.com/home/home-border-top-pissed2.php' +(clickCount/ clickSpacing)+'.php';

else(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location ='http://www.?.com/home/home-border-top-pissed3.php' +(clickCount/ clickSpacing)+'.php';

else(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location ='http://www.?.com/home/home-border-top-pissed4.php' +(clickCount/ clickSpacing)+'.php';

else(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location ='http://www.?.com/home/home-border-top-pissed5.php' +(clickCount/ clickSpacing)+'.php';

else(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location ='http://www.?.com/home/home-border-top-pissed6.php' +(clickCount/ clickSpacing)+'.php';
}

Rambo Tribble

5:14 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



% is the modulus operator. It returns the remainder of a division, so:
var mod=5%2 // mod==1
var mod=27%8 // mod==3

JAB Creations

7:11 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok I'm still a newbie regardless of how far I've come. Attach that explaination to how it determines clicks?

Ok so a % basically divides the combined numbers and spits out the nearest round number?

If that's the case I'm not sure what the goal is then?

Thanks for the help guys! If we get this working you can piss off my website and it'll still validate as XHTML 1.1 strict! I got my frame target to work this past weekend and I gotta thank the folks at this forum for it! :-)

Bernard Marx

9:37 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok so a % basically divides the combined numbers and spits out the nearest round number?
If that's the case I'm not sure what the goal is then?

Pretty much (the number after the % should be an integer). The situation gets more complicated where any negative numbers are concerned, and this is where the modulus operator diverges from the accepted behaviour of modulus in mathematics.

I'm more used to a modulus representing a cyclic mapping onto a restricted set of integers.
When you're a kid, it's introduced as "clock arithmetic". The hour hand on a clock goes round endlessly, but it's resticted to a set of integers.

In our case, to get the effect:

[blue]if(++clickCount > 12) clickCount = 0;[/blue]

we use:

[blue]clickCount = ++clickCount % 22;[/blue]

because:

[blue]// n=21
n % 22 -> 21

// n=22
n % 22 -> 0[/blue]

It has only saved a few characters, but it's a more flexible form, and I'd go as far as saying that is the used as standard in a any programming language that has the operator.

... and it didn't work.

Odd. There's been a bit of this recently.
Perhaps there's some copy and paste problem.

..oh hang on..

If you are using an XHTML strict doctype, that may have an effect on what the browser considers clickable.
Rambo..?

The second script only allows me to specify one url

The URLs in your example only differ by the integer on the end {1,2,3,..}. So it seemed a wasted opportunity not to do it like that. If the URLs actually differ in some other way too, then your original form will have to do. Using an array structure would be more succint, but..who cares?

This is a very simple scripting process, so I can't see a reason for any of the versions not to work, apart from
- doctype issues
- the way that the child frame's window object is referenced

In what way is it not working?
- Are clicks activating the function? (stick in an alert)

Rambo Tribble

2:24 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello, Mr. Marx.

If you're asking me about XHTML, you've probably got the wrong furry creature. I've done reading on the subject, but tend to consider XHTML more suitable for intranet projects than those for the wild and wooley web. Support for the X just doesn't seem quite there yet (that is not to say XML isn't essentially useful for data and web services).

I don't recall encountering anything that said XHTML put any restrictions on what was clickable. Even if it did, I'd question whether browsers would be so strict in its implementation. We tribbles aren't particularly good at strict. I'd always heard it was you English lads that fancied the discipline thing.

SpaceFrog

2:49 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



you should try using :

switch(clickCount){
case(4) : ....
break;
case...

Bernard Marx

3:23 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Contribution respected, SpaceFrog, but I disagree.

If the URLs only differ by the index that appears just before the file extension, then the application of a little arimetic leaves us only having to hard-code the constant part of the URLs once.

If the URLs are more different than that, then they could be put into an array, then (again) a little arithmetic is applied to dereference them.

The benefit of all this is that the 'click spacing' - how many clicks between each new URL - can be changed with a single value. Otherwise we'd have to go through and change all the numbers

[4,8,12,..]-->[5,10,15,..]
. Also, for lovers of code beauty, the URLs can be kept together in a list.

I agree that switch structures can be neater, if the only other option is an

if..else

Rambo, I was just wondering whether one is supposed to (scriptwise) apply the event handler to the BODY or HTML element instead, in this strict scenario.

We could just get round this by applying an HTML event handler to the BODY tag (as before), and give that anonymous function a name. We still don't know the actual details of the problem yet though.

SpaceFrog

3:35 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



Darn I hadn't noticed the similarity in the urls ...
so of course if modulo=0 then the result of division gives you final index...
Well done Bernard!

Should the urls have been totally different a switch would have been indicated ...

JAB Creations

2:07 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm defintly here to learn but I'm not at the level you folks are with JS. So if you're going to try something new or different you'll have to give me the full code so I can use it and possibly understand it IoI.

Still though it's not working.

Rambo Tribble

2:32 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although I can find no direct reference to the issue of applying an event handler to the HTML element, testing with the validator would tend to confirm that it is not supported on that element.

I appreciate your faith in my acumen, Mr. Marx, and would just like to take this opportunity to remind our readers of my motto:

"Rambo Tribble: If he doesn't know the answer, he'll make something up."

Bernard Marx

5:35 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My preferred style is obfuscation.

The presentation of some dense, apparently optimised, code renders me beyond suspicion, at least while it's being worked out. Fortunately, this is, more often than not, a great deal longer than it takes for me to write it.

(function(){var doo = this[(get[dweeb()]¦¦'jala jala')(n%42)]})('hello')

::Rambo::

I'd always heard it was you English lads that fancied the discipline thing.

Cheeky. I have only just noticed that one.

Bernard Marx

6:04 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Talking about the joys of rectitude, et les autres vices anglaises...

Here's what I did for a bit of strict punishment:

1. Copied the frameset from JAB's site.
The document at

/home/nm/

2. Also copied the document sourced in the frame named 'border'.
Otherwise, cross-domain restrictions would prevent my script test from working.
- changed the extension to

.htm
.

3. Copied a page from a well-known website, and purveyor of all things standards.
I then gutted the page, leaving only those declarations required to keep the the document goosestepping smartly in XHTML fashion.

This last page was used as the 'clicking' page, and I put it into the main frame of the set, and linked the script posted at #4 (+ a couple of additions for display).

----

Everything else was left in place.
Since all the necessary URLs in the docs are absolute, everything else was being sourced from JAB's server.

----

As I hoped, it all works fine (IE & FF). Playing the soundbites as required.

(and, I don't know why, but I don't get cross-domain problems after the first location change ...?)

----

Anyway, I have put the thing at the usual place. This does, I realize, involve some dirty hotlinking on a temporary basis (all in a good cause).

The URL is being stickied.

JAB Creations

10:38 pm on Feb 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good stuff! Thanks :-)