Results 1 to 3 of 3

Thread: putting the event handlers into the script

  1. #1
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question putting the event handlers into the script

    1) Script Title: iframe SSI 2

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...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...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

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    I don't see the script "Iframe SSI 2" on your page actually. Is your question independent of this script?

  3. #3
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •