473,385 Members | 1,919 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,385 software developers and data experts.

Show the frame name when I click it

manuelgk
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
2 1622
gits
5,390 Expert Mod 4TB
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(me.name); 
  5.     };
  6. "></iframe>
kind regards
Nov 13 '07 #2
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. }
  11.  
  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. }
  21.  
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

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

Similar topics

6
by: bayram guzer | last post by:
hi everybody, i have very strange error. i can not see some of the asp pages on my browser. when i look from view source, all the source is there but browser does not show anything, just an empty...
1
by: Bart Plessers \(artabel\) | last post by:
Hello, I am wondering if one could do following. I have a main frame with 3 subframes ("top", "left" and "contents") I have a link in the left frame, someting like: <a...
4
by: Michael | last post by:
Hi, I create site with a prefix FramSet layout. The main page contains HTML <Form> function like this <Form name=my_form method=post action=my_action.asp> <input name=search_string ...
1
by: Justin | last post by:
Hi, I have a simple frameset defined: ---------------- index.html ---------------- <FRAMESET COLS = "225,*"> <FRAME NAME = "a" SRC = "one.html"> <FRAME NAME = "b" SRC = "one.html">...
7
by: ABC | last post by:
I am a total newbie to javascript. I have only done Frontpage. I am trying to do a page of image show----I only managed to find a javascript to create pop up windows for the chosen image. Almost...
9
by: books1999 | last post by:
I have framset with leftFrame, mainFrame, TopFrame. I found this script : http://www.dynamicdrive.com/dynamicindex8/collapsemain.htm I wonder if it could be ajusted so that it collapses the...
7
by: shuki | last post by:
hello guys i'm newbie here so it might sound like a stupid quastion i have 4 frame - 3 on the left and one main on the right i have links in one of the small frame that changes the page on the...
2
by: PieOPah | last post by:
I have a webpage that uses frames (yes I know, frames - previously been flamed about that, but I do not know anything else to use since I am clueless!!! Been asked to cobble together a site since...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
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...

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.