Solved

how to call the function in iframe

Posted on 2004-08-02
6
301 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now