#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Nottingham - England (UK)
    Posts
    9
    Rep Power
    0
    Heya guys, I need help with this script, I can get it to pop up on page load, But cant stop that to make it pop up on a link command.

    I have page that loads a Pop up window on load which is DHTML and is dragable.

    The script:

    <SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
    <!--
    // This script handles the dragging and closing capabilities
    // of the DHTML popup

    //Declare, set global variables

    var selectedObj
    var offsetX, offsetY
    var divPosX, divPosY

    //Set the initial X,Y coords for the popup div
    divPosX = 15;
    divPosY = 15;

    //Detect browser verssion
    var IE4
    var coll, styleObj

    IE4 = (document.all) ? 1 : 0;

    if (IE4){
    coll = "all.";
    styleObj = ".style";
    }

    //return the DOM reference to the given style
    function getObject(obj) {
    var objRef
    if (typeof obj == "string") {
    objRef = eval("document." + coll + obj + styleObj);
    } else {
    objRef = obj;
    }
    return objRef;
    }

    //Close the DHTML popup window
    function hideElement(obj) {
    divRef = getObject(obj);
    divRef.visibility = "hidden";
    //event.srcElement.style.cursor = "pointer";
    }

    //Shift an object to given position
    function shiftTo(objRef, Xpos, Ypos) {
    objRef.pixelLeft = Xpos;
    objRef.pixelTop = Ypos;
    }

    //Only allow IE4+ to initialise DHTML popup, else display normal HTML popup window
    function init() {
    if (IE4) {
    initEvtHandling();
    initDiv('dhtmlpopup');
    } else {
    showHTMLPopup();
    }
    }

    function showHTMLPopup() {
    myWindow = window.open("popupURL","NAME","titlebar=no,HEIGHT=170,WIDTH=180");
    myWindow.moveTo(200,200);
    myWindow.focus();
    }

    //Assign the event handlers
    function initEvtHandling() {
    document.onmouseup = releaseElement;
    document.onmousemove = moveElement;
    }

    //Initialise the div
    function initDiv(obj) {
    divRef = getObject(obj);
    shiftTo(divRef, divPosX, divPosY);
    divRef.visibility = "visible";
    }

    function grabElement(obj,evt) {
    selectedObj = getObject(obj);
    calculateOffsets(evt);
    return false;
    }

    function calculateOffsets(evt) {
    mousePosXRef = window.event.clientX;
    mousePosYRef = window.event.clientY;
    offsetX = mousePosXRef - divPosX;
    offsetY = mousePosYRef - divPosY;
    }

    function moveElement(evt) {
    if (selectedObj) {
    mousePosXRef = window.event.clientX;
    mousePosYRef = window.event.clientY;
    divPosX = mousePosXRef - offsetX;
    divPosY = mousePosYRef - offsetY;

    shiftTo(selectedObj,divPosX,divPosY);
    return false;
    }
    }

    function releaseElement(obj) {
    if (selectedObj) {
    selectedObj = null;
    }
    }

    //-->
    </SCRIPT>


    So this how I set it to work= Load onload then go find the JS with pics written doc etc to show if IE4+ in a non window, just pics in the JS file but if the browser doesnt support it, will show the pics in a the size set window.

    what I cant seem to work out is how to make that script work on a click.

    Help Please
  2. #2
  3. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    38
    What happens when you put exactly what you put in the onLoad inside an onClick?
    Michael
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Nottingham - England (UK)
    Posts
    9
    Rep Power
    0
    Well ive tried that therory I think, If you mean by -

    <a href="file.html" onclick="showHTMLPopup()">Click to open popup</a> No go with that, is that what you meant?
  6. #4
  7. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    38
    Yes, that's what I meant, but more like: <a href="javascript:void(0)" onclick="showHTMLPopup()">. Even if it doesn't work, what does happen?
    Michael
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Nottingham - England (UK)
    Posts
    9
    Rep Power
    0
    Okay, that didnt work dude.

    This is what happend -

    as I clicked it opened a new window (Cannot be displayed) but the right size, but not the DHTML window, just an ordanary window. Hmmm...then also the main window opened the onclick command (cannot be displayed)

    Hmmm....Have you got ICQ? I need to explain and show you the script, its no ordanary script as a normal pop up window, so its hard to explain on here.
  10. #6
  11. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    GF: any of these will work -

    <a href="#" onclick="showHTMLPopup();return false;">Click to open popup</a>

    or

    <a href="&#106;avascript:showHTMLPopup()">Click to open popup</a>

    or

    <a href="&#106;avascript:void(0)" onclick="showHTMLPopup()">Click to open popup</a>


    This last is Michael's; for some reason, this editor is parsing the "java" portion of "javascript" and adding a space. I corrected it with a hack I've been using to post character entities (like &amp;nbsp;) - escape the ampersand with &amp;amp; to "fool" the parser (here it's a "j" - &amp;#106;). Someone fix this!!!


    If you don't return false from an onclick, the browser will proceed with the default action - loading the HREF into the main window.

    Always return your popup to a global variable for further scripting....
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Nottingham - England (UK)
    Posts
    9
    Rep Power
    0
    See that works BUT it pops up in a window, Not as the DHTML window.

    Okay, Ive found a example of use http://www.kitkat.co.uk See that Pop Up?

    Thats what I mean, see in IE 4 + you can drag it and close it, without the window around it! But in NS 5 - its a normal window with the pics.

    Understand now? and how can I make that script DHTML pop up work like a HTML pop up?
  14. #8
  15. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    38

    Talking Nice example!


    OK, first of all, stop referring to it as a window. Although it has the appearance of a window, it's a <div>. They are hiding the code from you in a .js file (see http://www.kitkat.co.uk/orangechunky_div.js). The ability to move the <div> dynamically is provided in part by the grabElement() function they are using. Ignore any code that has the word window in it -- it's probably not related.
    Michael
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Nottingham - England (UK)
    Posts
    9
    Rep Power
    0
    Yeh, I know its a Div layer dude, just that its getting late over here in England, bit tired.

    Hmmm....the script isnt in the .js file thats the writen images, to appear for the DIV. Thats what you seem to keep ignoring lol

    So can you help me?
  18. #10
  19. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    38
    Boy, it must late over there -- it's late over here. There's no such think as Netscape 5, so I'm assuming you mean 6.

    What they are probably doing is providing the cool-looking functionality for one browser and a substitue for the one(s) that don't support the code they are using. They have built several functions to handle different tasks and are using them in an object oriented sort of way.

    If you look at the code, each one is commented pretty well, indicating what each one does. The reason I pointed out the .js file was to show you parts of their code you may be overlooking.

    If you are getting only the window and you are using a browser that should support the DHTML version, chances are you aren't calling the correct function or the browser/object detection/logic is reversed or broken.

    Have you tried several different browsers? Does it happen identically on all of them? The onClick code I provided isn't going to adversely affect any of the other code. The only thing onClick provides is a method of triggering the respective function(s). For all it cares, you can do it as a mouseOver, or in an href, or even in a <script> at the bottom of the page.
    Michael
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Nottingham - England (UK)
    Posts
    9
    Rep Power
    0
    It cant, and wont work like that, I was thinking as Iam not such a scripter, If you can interigate that DHTML script into one .JS file and then maybe use it as a ordanary HTMLPop Up window, which you could, but would take some time and effort to get the output.

    so do you reckon that it could maybe able script that?

IMN logo majestic logo threadwatch logo seochat tools logo