PDA

View Full Version : 2 java scripts, 1 html document


andes
10-16-2007, 02:20 PM
Hi.

A long story short:

I'm using a CSS dropdown menu I found here
http://www.dynamicdrive.com/dynamicindex1/chrome/index.htm

... This is a .js which loads just fine, and works properly.

I'm also using a second .js which ain't working that well. The .js contains the following code:
function openOtherLinks(id1, id2) {
var link1 = document.getElementById(id1);
var link2 = document.getElementById(id2);
if(!link1.href || !link2.href)
return;
self.frames['left'].location.href = link2.href;
self.frames['main'].location.href = link1.href;
}

And the html heading contains among other things these lines:
<script type="text/javascript" src="java/meny.js"</script>
<script type="text/javascript" src="java/links.js"</script>
Where links.js contains the code i wrote above.

The links-script makes me able to make a "<a href" opening two targets at once, with each their targets (which in this case would be iframes).
Making parts of my html like this:

<a href="javascript: openOtherLinks('rotel1', 'rotel2')">Rotel</a>
<a href="javascript: openOtherLinks('tannoy1', 'tannoy2')">Tannoy</a>

... And the following anywhere outside the body:
<a id="tannoy1" href="tannoy_overview.html"></a>
<a id="tannoy2" href="tannoy_left.html"></a>
<a id="rotel1" href="rotel_overview.html"></a>
<a id="rotel2" href="rotel_left.html"></a>


Two examples of combinations I've trid:
http://www.risington.no/dynamikk/
- This one contains the links-script in the heading, and loads the dropmenu from the .js, which works out just fine in mozilla firefox and safari but NOT explorer. Tried out both 6.xx and 7.

http://www.risington.no/dynamikk/index2.html
- This one loads both the scripts external. But here the a href-part suddenly seems to be getting a slight problem. I'd believe it would be because of that the a hrefs is directed straight to a couple of tags in the script itself. But I'm far from no brain surgent when it comes to these kind of things.

1. Should the .js look different ? Or is this correct ?

2. Whenever I put the code in links.js directly in the heading of the html, it works but then it screws up the menu-script when the page is viewed in Explorer. (which was my problem at first).

3. Any ideas of how I could combine these scripts? Does it matter if I'm using them seperatly as .js-files or if I'm just putting it all directly into the heading? Is it ok to load one as an external js, as I put the other one in the heading?

Any help here would be awesome :=)

JoeyDaly
10-17-2007, 06:27 AM
I'm getting all sorts of errors:

links.js (line 9)
syntax error
}\n

index2.html (line 105)
lenkescript is not defined
lenkescript

javascript: openO... (line 1)
openOtherLinks is not defined


Hopefully that'll help you. It shouldn't be that hard to combine .js scripts I have alot of websites that reference 5-10 .js files and they all work perfectly fine, just ensure that you reference everything correctly.

andes
10-19-2007, 12:55 PM
Hi!

Thanks for helping out.
After even more reading through the codes, it suddenly occured to me that one of the id's/tags in the menu javascript is the same as the name of one of the iframes!

So, I renamed the iframe called "left" to "leftframe" and now it works just fine!

... You noticed some errors I wasn't aware of though, which is very nice. Doesn't seem to make any difference to the behavior, but shouldn't be nesseceary use code with faults in it ;)

Thanks for pointing it all out for me! :)