Display in new Window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mylog
    New Member
    • Sep 2007
    • 20

    Display in new Window

    I have a problem regarding open the enlarged image in a new window. What I am facing problem is I have to open put the image in the div from Javascript which I have done well and now what I need is when the user clicks on the image the image should be displayed in a new window. I have also tried this by using href option but when I put the window.open function into the href I original page gives an error which i do not want, I want the original page to be intact just opening the image in a new window. Is there any possible way. Here is what i have so far. Please could anyone customize the code so that I can open the image in a new window. Help greatly appreciated.

    [HTML]<html>
    <body>
    <div id="todiv">
    <table >
    <tr >
    <td id="abc"></td>
    </tr>

    </table>
    <a href="javascrip t:test();">Test </a>
    </div>
    </body>

    <script language="javas cript">
    function test(){
    var image = document.create Element('img');
    var a = document.create Element('a');
    image.src = 'boating.jpg';
    a.id = 'aID';
    image.id = 'imageID';
    document.getEle mentById("abc") .appendChild(a) ;
    document.getEle mentById("aID") .appendChild(im age);

    // document.getEle mentById("hID") .href = "javaScript:win dow.open('boati ng.jpg','','wid th=600,height=5 00, resizable=yes, scrollbars=yes' );"; //--->when i do this the original page gets lost
    document.getEle mentById("aID") .href = '#'; // --->done for keeping the original page intact

    document.getEle mentById("aID") .onclick = "javaScript:win dow.open('boati ng.jpg','','wid th=600,height=5 00, resizable=yes, scrollbars=yes' );"; //--->this script is not working

    }
    </script>

    </html>[/HTML]
    Last edited by gits; Mar 11 '08, 02:21 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    try this:

    [CODE=javascript]var func = function() {
    window.open(
    'boating.jpg',' ','width=600,he ight=500,resiza ble=yes,scrollb ars=yes'
    );
    };

    document.getEle mentById("aID") .onclick = func;
    [/CODE]
    kind regards

    Comment

    • mylog
      New Member
      • Sep 2007
      • 20

      #3
      Thank u very much. This worked perfectly.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        no problem ;) ... post back to the forum anytime you have more questions ...

        kind regards

        Comment

        Working...