473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

why a script won't work in an iframe?

On a page I have a table and one of the rows includes hidden divs in certain cells. There is a visible checkbox, which toggles the visibility and some other aspects of the display for the various divs.
Sample code in the table:
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2. <td style="width: 120px;"><div id="item1" style="width: 116px;" class="label">Cold Water</div></td>
  3. <td style="width: 20px;"><div style="cursor: pointer;" align="center"><a onclick="toggle('PFP1A','PFP1B','PFP1C','PFP1D','PFP1E'); toggletexton('item1');"><input class="checkbox" name="checkbox" type="checkbox"></a></div></td>
  4. <td style="width: 60px;" align="right"><div id="PFP1A" style="width: 41px;" class="label">Quantity</div></td>
  5. <td style="width: 30px;"><div id="PFP1B" style="width: 24px;"><input style="width: 20px;" value="combobox2" name="combobox" class="box"></div></td>
  6. <td style="width: 80px;"><div id="PFP1C"></div></td>
  7. <td style="width: 60px;"><div id="PFP1D"></div></td>
  8. <td style="width: 90px;"><div id="PFP1E" style="width: 90px;"></div></td>
  9. </tr>
  10.  
This script is in the head section:
Expand|Select|Wrap|Line Numbers
  1. function toggle() {
  2.     for ( var i=0; i < arguments.length; i++ ) {
  3.         $(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : 'block' );
  4.     }
  5. }
  6. function toggletexton() {
  7.     for ( var i=0; i < arguments.length; i++ ) {
  8.         $(arguments[i]).style.color = ($(arguments[i]).style.color != '#aaaaaa' ? '#aaaaaa' : '#000000');
  9.         $(arguments[i]).style.fontWeight = ($(arguments[i]).style.fontWeight != 'bold' ? 'bold' : 'normal');
  10.         $(arguments[i]).style.fontStyle = ($(arguments[i]).style.fontStyle != 'normal' ? 'normal' : 'oblique');
  11.     }
  12. }
  13.  
This works fine on the page. But once the page containing this is loaded into an iframe, the onclick events no longer fire. Same problem in Chrome, Firefox, Safari and MSIE.
Mar 16 '11 #1
3 2401
Dormilich
8,658 Expert Mod 8TB
this is due to the iframe being a separate HTML document, thus any Script or Styling from the parent document is not present inside the iframe.
Mar 16 '11 #2
Thank you Dormilich.

The script and styling are on the page that is the source for the iframe. I have other pages which load into the parent document (also into an iframe, each iframe in its own div; those divs are stacked on top of each other and a javascript in the parent document deals with which div gets displayed - all that works like a charm).
What is a mystery to me is why some of the pages display fine both as stand-alone pages and when displayed in the parent document's iframe, but this one only works in stand-alone fashion. I checked this out on multiple browsers.
Mar 16 '11 #3
Nobody seems to have an answer for me. To compound my confusion, for certain pages, in certain divs on the child page javascript from that page (script in the head section, function is called in "onclick" events in the body of page) works, and in other divs it does not. Go figure.
BTW, the two functions shown above, toggle nand toggletexton rely on the "$" function reproduced below. Could the way these?are set up be the culprit?
Expand|Select|Wrap|Line Numbers
  1. function $() {
  2.         var elements = new Array();
  3.         for (var i = 0; i < arguments.length; i++) {
  4.                var element = arguments[i];
  5.                if (typeof element == 'string')
  6.                        element = document.getElementById(element);
  7.                if (arguments.length == 1)
  8.                        return element;
  9.                elements.push(element);
  10.         }
  11.         return elements;
  12. }
Thanks all.
Apr 4 '11 #4

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

Similar topics

1
by: Jim | last post by:
Hey guys I DESPERATLY need some help with this small javascript i have on this website. All that it's supposed to do is change the button image once it's pressed but alas... I copy-pasted the code...
4
by: Wm | last post by:
I have a script that changes a main/enlarged image when you click on a thumbnail. It works fine in IE, but for some reason it won't do anything in Netscape 7.1. Does anyone know if this is a...
2
by: | last post by:
Simple script won't work. Why? function sendIt(module) { var flagged = document.form1.getElementById("e_flagger").value; if (module == 'test') { alert("Test OK:" + " " + flagged); } <form...
6
by: b. hotting | last post by:
Hi, I don't see why this won't work, it are 3 links, the last one (a get) does work, but the first 2 won't. i would like to use a post, through hidden input types any idea? thanks for your...
2
by: funkychicken818 | last post by:
This is the script. var reqTopCont; var reqBotCont; function changeTopContent(newUrl) { reqTopCont = false; // branch for native XMLHttpRequest object if (window.XMLHttpRequest) {
2
by: Altman | last post by:
I have created an ascx control and I am calling registerclientscriptblock. The path to the js file is relative to the aspx page and not the ascx file. The function runs fine in IE7 but in...
1
by: papalazarou78 | last post by:
Hi I've been experiementing with actionscripting transitions between sections... this is the first site I have tried this with (last 3 had swf loaded in one after another rather than transitioned...
7
by: Larry | last post by:
The below script, I have been using for many years, stopped working in IE 7.0 all of a sudden. It works using NS and Firefox. Anyone know why this is? Did something change in IE 7.0 that may be...
2
by: Matthew Wells | last post by:
Hello. I'm reposting this because my prioe post's subject line was incorrect. I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all the updates. I have an aspx page with...
5
tjc0ol
by: tjc0ol | last post by:
Hi all, I made contact page which allows visitors to input their name, email address, phone number, comments and select a comment type by using <select> element in html with javascript. Among the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.