Solved

how to call the function in iframe

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

691 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