Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to call the function in iframe

Posted on 2004-08-02
6
Medium Priority
?
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 500 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

604 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