By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Show the frame name when I click it

P: 54
Hello!, I just think about the possibility to detect something into the frames and I question me about click something into a frame and then (with js) get the name of this frame. I tried to get the frame names of an example web page and I put something like this:
Expand|Select|Wrap|Line Numbers
  1.   window.onload=function(){
  2.     for(x=0;x<window.frames.length;x++){
  3.       alert("This is a test\nOriginal frame: "+window.frames[x].name);
  4.     }
  5. }
As you see it appears me all the names of the frames contain in my web page but is there any way to make a click in any part of the frames and only shows the name of the clicked frame?

Thanks a lot
Nov 12 '07 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 5,390
hi ...

you could add an onclick-handler to the document within the iframe in case it is not from another domain, the following is an example:

Expand|Select|Wrap|Line Numbers
  1. <iframe name="test2" src="" onload="
  2.     var me = this;
  3.     this.contentDocument.onclick = function() {
  4.         alert(; 
  5.     };
  6. "></iframe>
kind regards
Nov 13 '07 #2

P: 54
Well, I tried your code and it works, but maybe I should be more specific in my question. The fact is I have my own code and it can detect the URL of a link, but when I try to know the origin of the clicked element contains in a frame it detect the URL but the origin (name of the frame) appear all the frames that I have. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. window.onload=function() {
  2.   for(x=0;x<window.frames.length;x++){
  3.     els=window.frames[x].document.body.getElementsByTagName('*');
  4.     for(c=0;c<els.length;c++){
  5.       els[c].onclick=function(){
  6.         getOnclicksm(this);
  7.       }
  8.     }
  9.   }
  10. }
  12. function getOnclicksm(el) {
  13.   cadena=new String("?COLAB_CLICK=YES");
  14.   var url=String(el.getAttribute('href'));
  15.   if (el.tagName=="A"){
  16.     for(z=0;z<window.frames.length;z++){
  17.       alert(el.href=el.href + cadena + "\nOrigen: " + window.frames[z].name);
  18.     }
  19.   }
  20. }
as you see I have an alert in my function "getOnClicksm"; it shows a URL with a different string and I want to show the origin frame too but I don't know how can I do.

Thanks again
Nov 13 '07 #3

Post your reply

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