Log in

View Full Version : putting the event handlers into the script



woodstock
12-20-2006, 11:28 PM
1) Script Title: iframe SSI 2

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm

3) Describe problem: There's no problem with this script. I have implemented it on a page to load content into the iframe. Next to the iframe is a set of links. In the mark-up I have inserted onclick events which work fine, but now I want to refine it and remove the javascript from the mark-up altogether. I've tried using the bit of script included below, and messed around with it a lot but can't get it to work.

function prepareLinks() {
alert("loaded")
if (!document.getElementsByTagName) return false;
if (!document.getElementById("no videolist"))
alert("no videolist");
if (!document.getElementById("no stobbit"))
alert("no stobbit");
if (!document.getElementById("placeholder"))
alert("no placeholder");
//these are just tests to see where the problem lies
//this is the functional bit:
var list = document.getElementById("videolist"); //a div tag containing the links
var links = list.getElementsByTagName("a");
var placeholder = document.getElementById("placeholder"); //the id of the iframe

for ( var i=0; i < links.length; i++) {
links[i].onClick = function() {
return loadintoIframe("placeholder",this);
}
}
}


window.onload = prepareLinks()

The bit of script that actually loads the content into the iframe is as follows:

function loadintoIframe(iframeid, url) {
if (!document.getElementById) return;
document.getElementById(iframeid).src=url
}

As mentioned this is working with the inline event handlers, as you can see by visiting the page in question following this link:

http://www.tonycaunce.pwp.blueyonder.co.uk/videomenu.html

The script in question is myiframe.js, which contains the three lines quoted above, plus the prepareLinks function and window.onload event. I've tried to place the link to the script at various places in the body of the page to test whether the document object has completely loaded before the script runs, that's what the tests at the beginning were for.
Anyway, I can't figure this out myself. I need help, if anyone can give me some pointers,

thanks

ddadmin
12-21-2006, 03:43 AM
I don't see the script "Iframe SSI 2" on your page actually. Is your question independent of this script?

woodstock
12-24-2006, 04:14 PM
Well to be honest the short answer is the script does not appear on my page, - it's in a separate file which I renamed myiframe so that I would be able to reference it, and it's no longer as it was because I did some pruning to get rid of the resize functions that I didn't need, but the "loadintoIframe" bit is the original from the script Iframe SSI, I'm not sure which version it was now. If this goes against the rules then please withdraw my question from the forum. Actually my question is not about the actual script but how to link the event handlers to it without putting javascript onclick events in the mark-up.