473,662 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script in an IFRAME not calling particular function defined in the parent document?

12 New Member
After following the instructions from the answer below:


http://bytes.com/topic/javascript/answers/153274-script-iframe-can-not-call-functions-defined-parent-document


I was able to have the child window perform the function in the parent window.

The function was to only have an alert window pop up as the child page was loading.

I easily modified this to my intention which was to have a parent function performed when the child window was clicked.

Using the body tag:

<body onclick="parent .FUNCTION NAME HERE()">

I first change the method in which the function would be triggered, all went well there. then I tried to change which function would be triggered. (Basically use the function I wanted to happen on click of the child window rather then the function from the test). Once I did this switch, nothing happens.

The site this is being used on is:


http://tylerpanesar.ca/


What I want is when the menu bar is opened, the user chooses a link and the menu closes and goes to that link. This already happens. However if the user opens the menu bar and then changes there mind and continues with the page the are currently on, the menu stays open.

The child window has the same code to call the parent function to call the menu.hide function, but it does not work.

Any help would be greatly appreciated.
Thanks in advance,
Tyler
Apr 10 '10 #1
22 3986
gits
5,390 Recognized Expert Moderator Expert
so ... just to clarify the task ... you want the menu to be closed when the mouse moves out of the menu ... or when the user clicks outside of it?

kind regards
Apr 12 '10 #2
thekingsnake
12 New Member
Currently it "hides" only when you choose one of the menu items, but it does not "hide" when you CLICK on your curent page. If you could figure out how to get it to "hide" on a "mouse out" that would be the better option.

I attempted this method however i could only get it to "toggle" the menu on "mouse out". This method does however create an annoying flicker when you hover of the menu items (as it is toggling the open menu command I guess). If I had it "hide" the menu on "mouse out" it would "hide" as soon as you moved off of the main button. The viewer doesn't even have a chance to click a link. or at least that is what happens when I did it. You may have a better method to achieve this.

The script that tells it to hide on click is within a jQuery function:

Expand|Select|Wrap|Line Numbers
  1. menua
  2.     .click(
  3.         function(){
  4.             menu.hide();
the code I used for the mouseout toggle was:


Expand|Select|Wrap|Line Numbers
  1. menu
  2.     .mouseout(
  3.         function(){
  4.             menu.toggle();
Any help is greatly appreciated.
Thanks,
Tyler
Apr 12 '10 #3
gits
5,390 Recognized Expert Moderator Expert
didn't check your code ... but the basic idea would be to assign the mouseout event to the expanded menu ... not to the menu button ... if you want me to check the code you should post the relevant parts here ...

kind regards
Apr 15 '10 #4
thekingsnake
12 New Member
Here is the script that I am currently using for the menu to open and the "click" hide feature.

This menu feature comes from the following help:

http://www.bennadel.co m/blog/1740-Building-A-Fixed-Position-Bottom-Menu-Bar-ala-FaceBook-.htm


Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.         jQuery(function( $ ){
  3.             var menuRoot = $( "#menu-root" );
  4.             var menu = $( "#menu" );
  5.             var menua = $( "#menu a" );
  6.             // Hook up menu root click event.
  7.             menuRoot
  8.                 .attr( "href", "javascript:void( 0 )" )
  9.                 .click(
  10.                     function(){
  11.                         // Toggle the menu display.
  12.                         menu.toggle();
  13.                         // Blur the link to remove focus.
  14.                         menuRoot.blur();
  15.                         // Cancel event (and its bubbling).
  16.                         return( false );
  17.                     }
  18.                 )
  19.             ;
  20.             menua
  21.                 .click(
  22.                     function(){
  23.                         // Toggle the menu display.
  24.                         menu.hide();
  25.                     }
  26.                 )
  27.             ;
  28.             // Hook up a click handler on the document so that
  29.             // we can hide the menu if it is not the target of
  30.             // the mouse click.
  31.             $( document ).click(
  32.                 function( event ){
  33.                     // Check to see if this came from the menu.
  34.                     if (
  35.                         menu.is( ":visible" ) &&
  36.                         !$( event.target ).closest( "#menu" ).size()
  37.                         ){
  38.                         // The click came outside the menu, so
  39.                         // close the menu.
  40.                         menu.hide();
  41.                      }
  42.                 }
  43.             );
  44.          });
  45.  </script>
Apr 16 '10 #5
gits
5,390 Recognized Expert Moderator Expert
you are using frames ... as you might have noticed your posted code already deals with clicks outside of the menu ... but the handling is only applied to the bottom frame's document where the menu-script is loaded. you might try to click ouside of the menu there and the menu closes. now you would just need to adopt that handling to the upper frame's documents ...

kind regards
Apr 17 '10 #6
thekingsnake
12 New Member
It's actually an iFrame that is 100% wide and high with the menu in the parent. I figured if I were to use regular frames it would not allow the menu to be seen past the frames edge.

I've tried adding the click to "hide" menu feature to the child document but there is now menu in that document for it to "hide".

What I was trying to was have the child document execute a function from the parent document and have that function executed IN the parent document. I've tried the technique from the link in my very first post but I believe it only calls the function from the parent and executes it IN the child. Which does not work for me as the menu is not in the child.

There should be a way to make the child execute a function FOR the parent.
Apr 17 '10 #7
gits
5,390 Recognized Expert Moderator Expert
if a function is in the parent and you want to scope the function to be executed there, then you might use the call or apply methods like:
Expand|Select|Wrap|Line Numbers
  1. parent.functionName.call(parent, arg1, arg2);
or
Expand|Select|Wrap|Line Numbers
  1. parent.functionName.apply(parent, [ arg1, arg2 ]);
kind regards
Apr 17 '10 #8
thekingsnake
12 New Member
I think I understand that.

Will I be able to use it in the body tag like I did here:

Expand|Select|Wrap|Line Numbers
  1. <body onclick="parent.FUNCTION NAME HERE()">
I'm rather new at trying to do this advanced stuff. I believe I am to put the name of the function I wish to execute in place of your "functionNa me", right?

Next I'm not sure how to use the "function name" I'm trying to apply.

From looking at my code, there is a script that contains a jQuery function. this function contains the "command" I am trying to apply. which is "menu.hide" . I tried simply using that and end up with:

Expand|Select|Wrap|Line Numbers
  1. <body onclick="parent.menu.hide.apply(parent, [ arg1, arg2 ])">
But that doesn't work. I think it's the
(parent, [ arg1, arg2 ])
section that has me confused. What are the arg1 & arg2 for?.

Perhaps I am applying the function using the wrong name?

Do I need to set a specific "var" within the jQuery function for just "menu.hide" ?

If so could I simply just do this:

Expand|Select|Wrap|Line Numbers
  1. var menuhide = $( "#menu.hide" );
and add this to the existing function:

Expand|Select|Wrap|Line Numbers
  1. menuhide
  2. function(){
  3. menu.hide();
Apr 17 '10 #9
gits
5,390 Recognized Expert Moderator Expert
try:
Expand|Select|Wrap|Line Numbers
  1. onclick="parent.menu.hide.call(parent, event);"
the arg1...n are parameters that might be passed to a function ... please first try it in FF ... might be that we would need a small adaption for IE?

kind regards
Apr 17 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
8431
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place this in the HEAD of my document - the page will wait until it downloads. If I place it in the BODY of my document - supposedly the page
2
4547
by: Randell D. | last post by:
Folks, I have got this working before, in part with some help from this ng but I never really understood how I got it working... and last time, I was using it via a popup window as opposed to an IFRAME. I've got several months of javascript under my belt and can resolve most things without errors in my Mozilla Javascript Console, but this one just does not do it for me. This is the picture:
26
45498
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function defined in "A.html", but every attempt results in an "is not a function" error. I have tried to invoke the function using parent.document.funcname(), top.document.funcname(), and various other identifying methods, but all result in the above...
3
1501
by: mike | last post by:
I have a document lets call it a.cfm that looks like: <iframe src="" id="test" name="test"></iframe> <div> <form name="myform"> ... many elements here </form> </div>
2
2955
by: P2P | last post by:
Hi I am wondering if someone know of a free cross-browsers vertical scrolling script that - is cross cross-browsers - will call the scrolling content from an external html page or from a url page
3
3328
by: Jeremy | last post by:
If we have an iframe loaded from the same domain as the parent document, how can we (is it possible) to execute a function on the parent document's page? e.g. 1) On parent page: ------------------ <script type="text/javascript">
1
3949
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
1
3531
by: SunshineInTheRain | last post by:
My project has 3 files, File1 has included master page. file1 consists of iframe1 that load file2. File2 consists of iframe2 that load file3. Javascript used on each file to resize the iframe height based on the each iframe's content height. It is work well on IE, but the error "has no properties" occured with firefox on code as below. Where both code is to get the id of iframe on file1....
1
4887
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to another page in the same domain which also contains infragistics datagid populated with default data retrieved from Data Base. After creating the frame I am attaching it to the HTML DOM and show it as modal popup with OK and Cancel Button inside an...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.