PDA

View Full Version : js within INCLUDED page in FP2003



richardleverton
04-27-2010, 09:47 PM
:confused:I'm attempting to use a DHTML script menu I downloaded from DynamicDrive

it works fine as downloaded, but I'm having trouble getting it to work in the website I"m building

1 - I want to put the script in an INCLUDE page which I can then include into each of the other pages.

2 - I have copied the appropriate code into my INCLUDE.HTM page , and it works fine when I preview it there - menu comes up and works as advertised

3 - I have INCLUDEd that page into my other pages - my understanding is that I shouldn't have to add any of the js code to any of the other pages

4 - I know the page is being included correctly, because I have a 'helloworld' in the included page , and it shows up correctly in all the other pages

5 - however, the menu doesn't appear on any of the other pages

can anybody please give me a hint ?

thanks :)
richard

djr33
04-27-2010, 10:56 PM
What do you mean "include"?
In PHP, include() is a function that merges two pages. Are you using PHP? Javascript? Etc.

If you are using any server side method (like PHP) to generate the pages, then remember that this just generates HTML.

So look at the final output source code (visit the page and view source) because this is what the browser sees (NOT any sort of complex processing on the server).

You will probably find that the final source code is messy.

For example, you might have two sets of <html> tags within each other if you include one full html page into another full html page.

The idea here is to figure out what's wrong and restructure the includes, etc., so that everything fits together nicely.

Beyond that, it's hard to say.

However, a VERY common problem with this sort of setup is that you include a page within another at a certain point, but SOME of the other page needs to be inserted at a specific point.

Due to this, it is very common that Javascript that needs to go in the <head> section will instead be inserted in the <body> section next to whatever other elements you are including.

To solve this you need to rework the whole setup in a complex way so that you include two different files in two different places (one in head and one in body) OR you could create a template generating system where you have a lot of complexity grabbing various parts from various locations and then after-the-fact building a full page. For example, you could make your final html output based on variables $head and $body and with each include just add to $head and $body. But this can get very complex, and really it's the same as just including in different places, just with a lot more layering.


Now I see that you're using frontpage-- if this is operating like PHP (which I am guessing it is), then the same principles should apply.

In short, regardless of how you put your pages together, the final html has to all be in the right order. If it's not, you're not putting the pages together in the right way-- reorder/reorganize something and it should work.

richardleverton
04-28-2010, 12:01 AM
HI DJR33

I'll try to speak to each of your points in order

a - INCLUDE is a feature of FrontPage by which you can insert a HTML page into another - in this case, I"m inserting a page with just the menu on it into every other page

b - not server side or PHP as far as I can tell

c - code isn't terribly messy ( but frankly , I don't care )

d - nope, not a full set of tags - at the point where the include is, the code says CODE]<!--webbot bot="Include" U-Include="include.htm" TAG="BODY" -->[/CODE}] where include.htm is the page being included

e - don't THINK i need to restructure the includes - seems like a fairly standard FP process

f - I understand it's hard to say

g - the whole page is inserted, see D above

h - yes, the instructions that came with the js specified some to go into the HEAD, and some into the BODY

i - you're right , what you are proposing sounds very complex, and would seem to be unnecessary given D above

j - yes , I'm using FP

k - again, don't think I need to reorder


the bottom line is that the thing works in one .HTM, but won't work in the rest. Surely somebody out there has used these javascript menus within front page and have used INCLUDE to put the menu on every page without having to code it into every page separately.

sure hope somebody who has done this speaks up.

thanks again for the help

regards
richard

djr33
04-28-2010, 12:19 AM
a- Yes, I see. I realized this after I'd written the rest. I usually use PHP. Frontpage does the same basic thing-- it takes one page and inserts it directly into another. Therefore it will have the same problems-- placing all of one page into another page. So splitting it like I described will help.

b- Correct, but it generates the same effect.

c- The HTML output is crucial; if it's just messy that's not really a problem, but keeping the code clean is essential for debugging and asking for help-- if someone can't read your code they can't help. Regardless, I understand that, but my point wasn't about it being messy, but about it being in the wrong order. Frontpage is grabbing code and dumping it where you tell it. I don't know everything about these options, but usually this means you'll have to reorganize the components so that they are placed in the right spot.

In other words:
<head>Your Javascript needs to go here.</head>
<body>Your content needs to go here.</head>

Since you already then have both of those established, you must include into BOTH rather than just merging them as-is into a single section. That will generate invalid and broken HTML. The result of this is:

<head>[missing Javascript]</head>
<body>Content AND Javascript both inserted here...</head>


The only other way I can think of to explain this is like you just bought groceries. Some are frozen and some are just kept cold. You have now designed an automated system to sort your food and put it away using frontpage. But frontpage doesn't work because all it does it place all of it into the refrigerator. None of it gets into the freezer as needed. This is because frontpage shouldn't just be grabbing all of it and dumping it into a single place but sorting it for you. Since frontpage doesn't do this for you, you'll need to include it separately.


Again, this is all based on the idea that frontpage isn't smart enough to figure out how to sort it into the right spot. From everything I know, it's not. Then again you might be able to look through the options and see what's going on.


Regardless, the whole point of this is that if you just look at your HTML output, I believe that you will not find the javascript split into the right sections. Based on that, you can see if this is the problem.

If the HTML in the output (on your website, after FP is done with everything) is correct, then I'm on completely the wrong track for fixing this. But if as I suspect it's out of order, then this will probably help.


The bottom line is that you need to compare the end result HTML to what you desire of the HTML, and then once you find the change/problem, you can go back to the process and find out how to do it better.

Personally this is why I don't like using programs like frontpage that make it "easier" when I can just do it myself and actually understand/control what's going on.