473,326 Members | 2,125 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,326 software developers and data experts.

Detecting frames...

manuelgk
Hi! how can I detect the frames in a web page with Javascript? I mean, I want to detect the frames and set an alert with all frames contain in a Web page.
Thanks again!!!
Oct 15 '07 #1
25 2654
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. window.frames[]
gives you all the frames within the current window object.
Oct 15 '07 #2
OK, thanks, and what is the difference between put "document" and not "window"? is it possible?
Kind regards
Oct 16 '07 #3
acoder
16,027 Expert Mod 8TB
The Document object doesn't have a frames collection while the Window object does.
Oct 16 '07 #4
Mmmm this is intersting because I found that document object could have a frame object . I don't know if I get confuse, if I am, I was wondering if you could explain me that.
Another thing, is it correct to put this?:
Expand|Select|Wrap|Line Numbers
  1. els=window.frames[].document.body.getElementsByTagName('*');
This is for read something or all the objects contain in the show frame document, I don't know if it could be possible.

Kind regards
Oct 16 '07 #5
acoder
16,027 Expert Mod 8TB
Mmmm this is intersting because I found that document object could have a frame object . I don't know if I get confuse, if I am, I was wondering if you could explain me that.
Try it in Firefox - I think you'll get an error.
Another thing, is it correct to put this?:
Expand|Select|Wrap|Line Numbers
  1. els=window.frames[].document.body.getElementsByTagName('*');
frames[] is an array, so you want to access one frame at a time, e.g.
Expand|Select|Wrap|Line Numbers
  1. els=window.frames[0].document.body.getElementsByTagName('*');
Oct 16 '07 #6
Well, I allways use Firefox and as you said it detect some errors.
If I want to detect something like a handling event in a frame, how can I do it? I think I need to determine how many frames exist in a web page and loop that frames right?, would you like to give an example if it is possible?.
By the way, I tried to adapt to my code that you had seen before, I know I bug you with the same thing but I tried to make grow-up this script with different Web formats, so I modified the line "els=..." but I think I'm wrong:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prueba Frames</title>
  4. <script type="text/javascript">
  5.  
  6.       window.onload=function() {
  7.              <!--modify line, but it doesn't work!!! :( -->
  8.               els=window.frames[0].document.body.getElementsByTagName('*');
  9.                 for(c=0;c<els.length;c++){
  10.                   els[c].onclick=function(){
  11.                    getOnclicks(this);
  12.                   }
  13.                  }
  14.          }
  15.  
  16.              function getOnclicks(el) {
  17.              cadena=new String("?COLAB_CLICK=YES");
  18.              var url=String(el.getAttribute('href'));
  19.              if (el.tagName=="A"){
  20.                  alert(el.href=el.href + cadena);
  21.                  }
  22.  
  23.              }
  24.  
  25.      </script>
  26.  
  27. </head>
  28. <FRAMESET cols="20%,80%" title="" onLoad="top.loadFrames()">
  29. <FRAMESET rows="30%,70%" title="" onLoad="top.loadFrames()">
  30. <FRAME src="jo4.html" name="lol" title="Jo41">
  31.  
  32. <FRAME src="jo2.html" name="packageFrame" title="All classes and interfaces (except non-static nested types)">
  33. </FRAMESET>
  34. </html>
Thank you
Oct 16 '07 #7
acoder
16,027 Expert Mod 8TB
To loop through frames, try something like:
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < window.frames.length; i++) {
  2. // now window.frames[i] would be the current frame in the loop
  3. }
Oct 16 '07 #8
Ok thanks, I tried yet and it seems that work normaly. When I put an alert to know how many frames I have in the window the alert does not appear. This is my test code:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prueba Frames</title>
  4. <script type="text/javascript">
  5.  
  6.       window.onload=function() {
  7.               for(c=0;c<window.frames.length;c++){
  8.                  getjojo(c); 
  9.                   }
  10.                  }
  11.          }
  12.  
  13.          function getjojo(r) {
  14.            alert(r);
  15.       }    
  16.      </script>
  17.  
  18. </head>
  19. <FRAMESET cols="20%,80%" title="" onLoad="top.loadFrames()">
  20. <FRAMESET rows="30%,70%" title="" onLoad="top.loadFrames()">
  21. <FRAME src="jo4.html" name="lol" title="Jo41">
  22.  
  23. <FRAME src="jo2.html" name="packageFrame" title="All classes and interfaces (except non-static nested types)">
  24. </FRAMESET>
  25. </html>
I think when I pass the parameter should work. I also tried to eliminate the function but I obteined the same results :(. What can I do?.
Kind regards
Oct 18 '07 #9
acoder
16,027 Expert Mod 8TB
You've got some syntax errors in your code. Check your brackets.

You have two frameset tags.

Do you just want the total length or an alert for each frame?
Oct 18 '07 #10
I just want to show the total frames in my page with an alert, not an alert in every frame.
Oct 18 '07 #11
acoder
16,027 Expert Mod 8TB
I just want to show the total frames in my page with an alert, not an alert in every frame.
Then forget the for loop and just try:
Expand|Select|Wrap|Line Numbers
  1. alert(window.frames.length);
Oct 18 '07 #12
Well at list send me an alert with "undefined" message, I put away th window.onLoad=function and it works; if I put this it doesn't work...
Thanks again
Oct 19 '07 #13
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. window.onload=function() {
  2.   alert(window.frames.length);
  3. }    
  4.  
should work. Have you still got two frameset tags (with the onload in one of them)?
Oct 19 '07 #14
Ok, I tried this code with and without the 2 frameset tag and nothing happend :(, I don't know why. Even the undefined message doesn't appear anymore!!!
Oct 19 '07 #15
acoder
16,027 Expert Mod 8TB
Ok, I tried this code with and without the 2 frameset tag and nothing happend :(, I don't know why. Even the undefined message doesn't appear anymore!!!
I meant removing one frameset tag.

The onload in the frameset is probably overriding the window.onload.
[HTML]<FRAMESET rows="30%,70%" title="">[/HTML]
Oct 19 '07 #16
Nop, I put away these things and nothig, I start to think that this could be not posible. In the other hand I think it should be a way to detect them (not exactly show in an alert) and work with the document that frame has in. What tho you think? could be the right anwser to this problem?
Thanks
Oct 19 '07 #17
acoder
16,027 Expert Mod 8TB
This example works:
[HTML]<html>
<script type="text/javascript">
window.onload=function() {
alert(window.frames.length);
}
</script>
<frameset rows="50%,50%">

<frame src="frame_a.htm" />
<frame src="frame_b.htm" />

</frameset>

</html>[/HTML]
Oct 19 '07 #18
Yeah! it works, I see that I had a mistake in the code ("length" and not "lenght") and it works now. Only I have a question, as you said I put off the "onLoad" in the frameset tag and it works, is there any way to do the same thing with the function "onLoad" in the frameset tag?.
Thanks
Oct 19 '07 #19
acoder
16,027 Expert Mod 8TB
Only I have a question, as you said I put off the "onLoad" in the frameset tag and it works, is there any way to do the same thing with the function "onLoad" in the frameset tag?
Do you mean call the function in the frameset tag's onload inline?[HTML]<frameset cols="50%,50%" onload="youMeanHere()">[/HTML]
Oct 20 '07 #20
Nop I meant put window.onload=function without put off the onLoad in the frames like this:

Expand|Select|Wrap|Line Numbers
  1. window.onload=function{
  2. ...
  3. }
  4.  
  5. <FRAMESET rows="30%,70%" title="" onLoad="top.loadFrames()">
  6. </html>
Is it possible?
Thanks
Oct 22 '07 #21
acoder
16,027 Expert Mod 8TB
Nop I meant put window.onload=function without put off the onLoad in the frames like this:
Add "top.loadFrames()" as an extra statement in window.onload.
Oct 22 '07 #22
Yep!!! it works but maybe I didn´t understand you at all when you said something about the "loadFrame". The fact is that this "loadFrame" is a function made by the original autor XD. By the way, is there any way to call or get the frame name propierty? as you know the frames have names, I think I could control the frames calling them by their own names. Is it possible?
Kind regards
Oct 25 '07 #23
acoder
16,027 Expert Mod 8TB
Yes, it's possible. See this link.
Oct 25 '07 #24
Thanks I already made it!!! thanks a lot!!! XD
Nov 2 '07 #25
acoder
16,027 Expert Mod 8TB
You're welcome. Glad you got it working.
Nov 2 '07 #26

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

Similar topics

4
by: Catherine Lynn Smith | last post by:
Is there a way in ASP to figure out if a page that is being loaded is being loaded into a frameset? I know I can code this in javascript, but I would prefer to only inject a chunk of 'onload' code...
3
by: foldface | last post by:
Hi Given a web page using frames, is there anyway the left frame can request a page in the right frame and, most importantly, detect when it has fully loaded? Ideally this requires no changes to...
3
manuelgk
by: manuelgk | last post by:
Hello everybody!!, as you see I have been trying the "urls-click detector" in my example pages and in other pages of the Web. Yesterday, I downloaded the JDK and as you know it has its own tutorial...
3
jhardman
by: jhardman | last post by:
I have an old site built with frames, and I plan to leave it in frames for now. The problem is that occasionally I find links (from outside) lead me to just the content frame which means most of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.