tags:

views:

43

answers:

1

I'm trying to open a new window from another pop up java script window via writing html code in this pop up window, but it doesn't work, please help me as soon as possible.

 <html>
          <head>
          <style>
        .larger{ width:750px;}
        .standard{ width:600px;}
        .orginal{ width:10px;}
         </style>

            <script type="text/javascript">

            function  larger()
            {
            OpenWindow=window.open("", "larger","width=1000,scrollbars=yes"); 
            OpenWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'+
            'http://www.w3.org/TR/html4/strict.dtd"&gt;'+
            '<html><head><title>Test page</title>'+
            '<style type="text/css">'+
            '.larger{ width:750px;}'+
            '</style></head><body>');
            OpenWindow.document.write('<a  href="#" onclick="standard()">high</a>');
            OpenWindow.document.write("<img id='img1' src='webfonts.jpg'>");
            OpenWindow.document.write('</body></html>');
            OpenWindow.document.close();
            OpenWindow.document.getElementById("img1").className = "larger";

         }
             function  standard()
        {
        OpenWindow=window.open("", "newwin",'width=600,scrollbars=yes'); 
        OpenWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'+
            '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;'+
            '<html><head><title>Test page</title>'+
            '<style type="text/css">'+
            '.standard{ width:600px;}'+
            '</style></head><body>');
        OpenWindow.document.write("<img id='img1' src='webfonts.jpg'>");
        OpenWindow.document.write('</body></html>');
        OpenWindow.document.close();
        OpenWindow.document.getElementById("img1").className = "standard";
         } 
        </script>
    </head>
    <body>
    <img  class="orginal"id="img1" src="webfonts.jpg" border="0" />
    <span   onclick="larger()"><a href="#">fig1</a></span>
    </body>
    </html>
A: 

You have created the standard function in the first parent script and you are trying to call it from the child pop-up window, which would offcourse not find this function defined within it.

anand
yes you are right, so how a function could be written in new window?
loll
the same way as you are writing the other contents in the new window. use document.write and insert the javascript tags with the required function definition.
anand
could event handlers help me?
loll
I tried to do this but it resulted in invalid code
loll
can you paste your code here that you tried?
anand