Solved

how to call the function in iframe

Posted on 2004-08-02
6
304 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript/Java - Changing an image background color 4 54
Allow space in this pattern 2 47
Angular - "nest" service calls? 18 22
Recordset containing single quotes 8 21
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now