Announcement

Collapse
No announcement yet.

JAVA - How to contain iframe within parent window / Webpage

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • JAVA - How to contain iframe within parent window / Webpage

    How would i code this to introduce a containment area within the webpage that the iframe is embedded into please... I have tried everything i can and managed to code it into jscript, but run into further issues, so i now need to code the JAVA with containment instead.

    here is the JAVA code


    var selected = null, // Object of the element to be moved
    x_pos = 0, y_pos = 0, // Stores x & y coordinates of the mouse pointer
    x_elem = 0, y_elem = 0; // Stores top, left values (edge) of the element

    // Will be called when user starts dragging an element
    function _drag_init(elem) {
    // Store the object of the element which needs to be moved
    selected = elem;
    x_elem = x_pos - selected.offsetLeft;
    y_elem = y_pos - selected.offsetTop;
    }

    // Will be called when user dragging an element
    function _move_elem(e) {
    x_pos = document.all ? window.event.clientX : e.pageX;
    y_pos = document.all ? window.event.clientY : e.pageY;
    if (selected !== null) {
    selected.style.left = (x_pos - x_elem) + 'px';
    selected.style.top = (y_pos - y_elem) + 'px';
    }


    }

    // Destroy the object when we are done
    function _destroy() {
    selected = null;
    }

    // Bind the functions...
    document.getElementById('draggable-element').onmousedown = function () {
    _drag_init(this);
    return false;
    };

    document.onmousemove = _move_elem;
    document.onmouseup = _destroy;



    AND HERE IS THE IFRAME CODE -

    <head>
    <style type "text/css">
    #frame1position{
    position:absolute;
    top:610px;
    left:935px;
    z-index:999
    }
    </style>

    </head>

    <div id="draggable-element">

    <div id="frame1position"; style="z-index:999;">

    <div id="frame1">

    <font face="impact" size="2">

    <CENTER> grab here/CENTER></font>

    <iframe name="frame1" src="DEMO.html?interframe=true" style="border:0; draggable="true" width="149" height="275" scrolling="no" horizontalscrolling="no" verticalscrolling="no" frameborder="transparent";"></iframe>
    <font face="impact" size="2">

    <CENTER>LINKMYWEBSITE.CO.UK</CENTER></font>

    <script type="text/javascript" src="java.js"></script>

    </div>
    </div>
    </div>
    </body>
    </html>

    I am not sure how to add a containment , i amagine as allways that it is a very simple code, but i am very new to JAVA & JS and its taking me a very long time just to work out the basics at present, so any help would be a great addition for my experience. Thank you.
Working...
X