Solved

how to call the function in iframe

Posted on 2004-08-02
6
307 Views
Last Modified: 2012-06-27
hi

i have one jsp enterId.jsp

in this jsp

i will have one iframe in this jsp

<iframe id=iframeHAWB_LABELS  style='width:0;height:0;'></iframe>


when i click submit button i will call printpages function


function printPages()
      {
            obj = document.getElementById("iframeHAWB_LABELS");
            obj.src = "etrans/air/ETAHouseDocLabelPrint.jsp?houseDocId="+document.house.houseDocId.value;
            obj.focus();
            msg = "Do you want to Print Lables using default printer ";
            if(confirm(msg))
            {
                        iframeHAWB_LABELS.sendPageToPrinter();
            }
            else
            {
                  iframeHAWB_LABELS.print();
            }
            return false;
      }


in ETAHouseDocLabelPrint.jsp i write sendPageToPrinter function like this

function sendPageToPrinter()
      {
      alert("sendPageToPrinter")
            }

at printPages() function i am getting error  object doesnt support this property or method

at this line
    iframeHAWB_LABELS.sendPageToPrinter();
how to call this function from Enter.jsp

with regds
chaitanya
0
Comment
Question by:chaitu chaitu
  • 3
6 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 125 total points
ID: 11693224
I'm a little confused about what you're asking about, but if your problem is how to call a javascript function located in the IFRAME-file, you could do it like this:


1) Try to name your IFRAME

<iframe id=iframeHAWB_LABELS name=iframeHAWB_LABELS  style='width:0;height:0;'></iframe>

and then 2) call then function like this:

self.frames['iframeHAWB_LABELS'].sendPageToPrinter();

Batalf
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11694167
The important information is in upper comment, but a bit confusing.
Therefore I do repeat it:
1.) Add the name attribute in your iframe tag.
2.) Access the iframe in your  printPages() function like this:

function printPages()
    {
         obj = self.frames.iframeHAWB_LABELS;
         obj.src = "etrans/air/ETAHouseDocLabelPrint.jsp?houseDocId="+document.house.houseDocId.value;
         obj.focus();
...and so on.

0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 125 total points
ID: 11694211
Sorry, I just noticed that your function contains also typos.
Here the revised function:

function printPages()
    {
         obj = self.frames.iframeHAWB_LABELS;
         obj.src = "etrans/air/ETAHouseDocLabelPrint.jsp?houseDocId="+document.house.houseDocId.value;
         obj.focus();
         msg = "Do you want to Print Lables using default printer ";
         if(confirm(msg))
         {
                   obj.sendPageToPrinter();
         }
         else
         {
                      obj.print();
         }
         return false;
    }


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11694236
Sorry again.
The focus() has to be near the print() call:

       else
        {
                     obj.focus();
                     obj.print();
        }


Also you could experiance timing problems if the page loading with new src into iframe takes longer then the confirm() request.

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question