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

trying to identify whether a particular iframe is existing in a page

i have used the below code to find out , whether the below named "rightnav" iframe is existing. But when i use this code it throws object required error. Expecting your help on this



Expand|Select|Wrap|Line Numbers
  1. <script lanquage="Javascript">
  2.  
  3.  
  4. if(window.document.getElementById('1').title=="rightnav")
  5. alert("got it");
  6.  
  7.  
  8.  
  9.  
  10. </script>
  11.  
  12.  
  13. <iframe id=1 title="rightnav"src="http://www.google.com"></iframe>
Aug 9 '08 #1
5 1254
acoder
16,027 Expert Mod 8TB
There are two problems. One is that you're testing before the iframe even appears in the source. Secondly, by using a property to test, you're assuming the object already exists.

To test the existence of an element/object, use something like:
Expand|Select|Wrap|Line Numbers
  1. if (document.getElementById("iframeID")) {
  2. ...
onload, i.e. after all elements have loaded.

There are two other problems with your code. One is that the script language attribute is deprecated. Use the type attribute instead: type="text/javascript". Secondly, IDs should not begin with a number.

Finally, please use code tags when posting code. See How to Ask a Question. Thanks.
Aug 9 '08 #2
hi i have understood my problem in the previous question, i have modified my my code but still i am getting "variable has no properties error", hope you would give me your valuable advice.


To automatically refresh all the iframes in my web page


i have tried to get my iframes's name in a variable called nam, and using that variable i am trying to refresh it, but i am getting nam.location.reload is null or not an object error in Ie, in firefox i am getting nam.location has no properties error.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <script  type="text/JavaScript">
  4.  
  5. function refreshme()
  6. {
  7.  
  8.  
  9. for(i=0; (a = document.getElementsByTagName("iframe")[i]); i++) 
  10. {
  11.  
  12. nam=a.getAttribute('name');
  13.  
  14. alert(nam);
  15.  
  16. if(nam)
  17.  
  18.  nam.location.reload();
  19.  
  20. }
  21.  
  22. }
  23. </script>
  24.  
  25.  
  26.         <a  href="#" onClick="javascript:refreshme();"> refresh</a>
  27.         <iframe src="http://www.google.com" name="doc"></iframe>
  28.  
  29.           <iframe src="http://www.w3schools.com" name="doc1"></iframe>
  30.  
  31.  
  32.  
  33.  
  34.  


i could get an alert, the alert properly gives me the frame name, and using doc.location.reload(); is also working for me, but i am not able to make use of the variable which has the frame name to refresh the the same frame.
Aug 11 '08 #3
acoder
16,027 Expert Mod 8TB
nam is the name of the frame, not the frame itself. That's what you've set as variable a. So use a.location.reload() instead.

PS. for code tags use square brackets [], not the angle brackets, <>.
Aug 11 '08 #4
"a.location.reload" does not work,
but a.contentWindow.location.reload();
works fine.

Thanks for the help. really happy to a memeber of this forum.
Aug 12 '08 #5
acoder
16,027 Expert Mod 8TB
"a.location.reload" does not work,
but a.contentWindow.location.reload();
works fine.
That would be for IE. If you want cross-browser code in one line, use window.frames[frameName] syntax.

Thanks for the help. really happy to a memeber of this forum.
Glad to hear it!
Aug 12 '08 #6

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

Similar topics

3
by: Hugh G. Johnson | last post by:
I have a knowledgebase (KB) system I installed into my existing dynamicly driven site. I used iFrame to grab the KB and place it in the content area of the page. This works great, but I realize now...
1
by: Andy Roger | last post by:
Hi everyone. I have an IFRAME that loads a user-specified document, but I need to set the below styles of the document in the IFRAME otherwise it'll look ugly. How can I effectively "inject"...
5
by: VB Programmer | last post by:
I have an ASPX page that is used for content. I have a master page which sticks the page in an IFrame. Question: From the content/ASPX page, I can't seem to reference request.querystring. Any...
3
by: GSL | last post by:
Hello, I'm building an application that will be incorporated into existing websites. I'd like to use the IFrame tag to accomplish this, but now I'm having second thoughts based on all of the...
2
by: jordan.weberflink | last post by:
I built a new module for an existing ASP based web application. I was asked to put the new module (ASPX page with ASCX user controls) into an IFRAME on an asp page. The IFRAME src attribute points...
5
by: pbd22 | last post by:
Hi. I am trying to poll a long-running process via a hidden IFrame. I am noticing that the online errata gives advice for handling a server response: window.parent.handleServerResponse(); ...
1
by: chaitanyadotcom | last post by:
As per my application i need to create tabs using iFrame dynamically. There are totally 4 buttons in my application where for each button i provide a link. Where in it will dynamically create a tab...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.