Body Tag Question
Barb
Administrators Posts: 3,352 SmugMug Employee
First off, forgive my complete and total ignorance on this subject!
I am running one javascript on my site - the referral one (where when you click on the smugmug link at the bottom, your referral code is attached to it). It works fine. However, when I placed the code that was required in the "body tag" section, my nav bar disappears across the top of my page. However, if I place the body tag code in the "Head tag" section, my nav bar reappears and the code works as it should.
I have wanted to try a couple of the other javascript codes floating around the forum lately (brilliant stuff!), but they don't work if I place the code in the "Head tag", and again, if I place the code correctly in the "Body tag" section, my nav bar disappears! Does any of this make sense?
I am running one javascript on my site - the referral one (where when you click on the smugmug link at the bottom, your referral code is attached to it). It works fine. However, when I placed the code that was required in the "body tag" section, my nav bar disappears across the top of my page. However, if I place the body tag code in the "Head tag" section, my nav bar reappears and the code works as it should.
I have wanted to try a couple of the other javascript codes floating around the forum lately (brilliant stuff!), but they don't work if I place the code in the "Head tag", and again, if I place the code correctly in the "Body tag" section, my nav bar disappears! Does any of this make sense?
0
Comments
[php]
<body onload="doOnLoad();delHover();OnLoadHandler();updateSS();killFullscreen();">[/php]
Portfolio • Workshops • Facebook • Twitter
barb, there is a new easier way to do all of this.
take all that code out of your body and put this at the top of your javascript:
addEvent(window, 'load', doOnLoad);
addEvent(window, 'load', delHover);
addEvent(window, 'load', OnLoadHandler);
addEvent(window, 'load', updateSS);
addEvent(window, 'load', killFullscreen);
now whenever you need to add another function to run at the load event, just add another line of script.
I have never seen the function addEvent. Is this a standard JavaScript function/method for the window object?
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
Lee, wow, that will be much easier and will certainly take care of my problem. However, I added that to the top of my javascript and now my referral thing doesn't work. ??
Smug since 2006
SmugMug Help
PhotoscapeDesign
d00d that's my body tag - just to be clear. And so you are a-sayin' that I should change it, too?
Portfolio • Workshops • Facebook • Twitter
Maybe one of the functions used by the call to addEvent prevents the others from executing (it returns true). If you want to be sure that all of them are executed regardless of their return value, you can do this:
addEvent(window, 'load', function() { doOnLoad(); delHover(); OnLoadHandler(); updateCSS(); killFullscreen(); });
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
That's MY code NOT Barb's. Barb - be careful ... make sure you don't copy paste the worng stuff
Portfolio • Workshops • Facebook • Twitter
Anton, doing it this way works for me. Thank you! I'm still curious as to why putting something in the "body tag" section would mess with my nav bar. Any ideas?
Smug since 2006
SmugMug Help
PhotoscapeDesign
Right Andy. I noticed there were things in there that I'm not using, so I took them out
Smug since 2006
SmugMug Help
PhotoscapeDesign
Maybe she copied and pasted your code.. then it should work for her as well
But, yes Barb, be carefull. Check if you're not calling non-existing functions (for your site), because they exist only in Andy's script.
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
Probably just a freakin' typo
I have to see what was in your original body tag section and the actual body tag generated by Smugmug (view source)
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
Well that's always a possibility! I've deleted it out of the body tag, as the other way works
Smug since 2006
SmugMug Help
PhotoscapeDesign
lol, whoops. i thought you posted barbs tag.
you can change if you want. or not.
it's very new age separation of content and behavior. so web 2.0.
its a function that lives in the standard smugmug scripts.
it actually encapsulates the IE specific attachEvent method and the w3 DOM addEventListener method
i've been using it in personal stuff and found it one day when i was digging through the SM code
barb, make sure you actually have the functions that that code i gave you calls. i didnt realize that was Andy's code i gave you.
make sure you replace all the function names with the ones you had originally in your body tag.
sorry!
Sweet! That saves some browser-specific coding.
Will this function always be available (i.e. is this function 'officially' supported and won't it go away in future versions of smugmug)?
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
Already did that, Lee. Thx!
Smug since 2006
SmugMug Help
PhotoscapeDesign
they (sm) use it all over the place, so i dont think it's going anywhere
even if it does, its all of about 10 lines of code. easy to add back in.
Want faster uploading? Vote for FTP!
functionally, in terms of program execution? no i suppose not.
In general:
If you don't have access to the (generated) HTML code, i.e. you can not add an onload="doSomething();" to a <body> tag or an onclick="doClick();" in a <DIV> element, then the addEvent is the only way to go.
But smugmug allows you to change the <body> tag.
So, for smugmug: Nope, no difference or advantage.
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
Want faster uploading? Vote for FTP!
samir,
There is another option which hasn't been discussed here.
Both the onload or addEvent() methods are only triggered once the page has fully loaded, including thumbnails etc. The disadvantage of these method is there is sometimes a delay between the page starting to load and the page becoming loaded, so I you are adding or removing elements from the page, the addition or removal becomes obvious to the user.
The other method is to place a script block in the footer. Doing this means that the functions will be called on the first pass of the code, and will result the visual issues being reduced, if not removed.
Cheers,
David
SmugMug API Developer
My Photos
Want faster uploading? Vote for FTP!
You're correct about the delay and the visual issues that may arise from it. But take note however that the DOM (the document object model, the structure of HTML elements that the javascript can access) may not be complete before the 'onload' event of the <body> has been fired!!
It depends on the browser, but querying/changing the DOM before the entire document has finished loading may return inconsistent/undefined results.
When I hear the earth will melt into the sun,
in two billion years,
all I can think is:
"Will that be on a Monday?"
==========================
http://www.streetsofboston.com
http://blog.antonspaans.com
This will require some careful testing before implementation.
Want faster uploading? Vote for FTP!