Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document is undefined 1

Status
Not open for further replies.

JRye

Technical User
Nov 14, 2008
8
US
I have an IFrame coming into a jsp page. I'm using this java script to call the correct url. It works in I.E., but in Firefox I get a error messages that says "document is undefined", which as you can see, is true. I tried x=document, but not good enough. Can anyone tell me what I have to include in the scipt to define the doc correctly? Thank you for your help.

<script language="javascript">
document.exchangeIndicesModule.location="<%= exIndModuleURL %>";
</script>
 
Perhaps showing more code, or a URL would help to understand what you are trying to achieve... I say this because 'document' doesn't need to be defined - it's part of the global 'window' object.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
You'll need to let us know where this code lives - on the parent page or on the iframe page.

Regardless, you probably need to do some reading on cross-document communication with javascript (wrt iframes).

As Dan says, some more code (or more usefully a URL) would be useful.

Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
One of the URL's with this iframe on it is:


and below is all the code from the one of the view jsp's. We are using a blank.html page in the src tag because we are behind a secure protocol. If I put the individual URL feeds coming into the IFrames in src tag, everything is fine, but we have multiple sites sharing the portlet, so we had to define the URL's for the IFrames inside a java class. Please let me know if you have any suggestions.

<%@ page session="false" contentType="text/html" import="javax.portlet.*,com.aegon.us.afp.marketwatch.*" %>
<%@taglib uri=" prefix="portlet" %>
<portlet:defineObjects/>

<div id="marketwatch">

<%
MarketWatchViewBean viewbean = (MarketWatchViewBean)request.getAttribute("viewbean");
String exIndModuleURL = viewbean.getExchangeIndicesURL();
System.out.println("exIndModuleURL in nviewbean is *** "+exIndModuleURL);
System.out.println("exIndModuleURL in nviewbean is *** "+renderRequest.getWindowState());
/*
* Portal Server seems to be storing the window state of the portlet.
* This is causing problem whenever portlet is rendered in maximized mode and the user
* leaves to another page and come back to the original page. In that situation
* the portal server is rendering the portlet in maximized mode eventhough
* the page has other portlets.
* The following logic is to fix the above problem.
*/
if (renderRequest.getWindowState().equals(WindowState.MAXIMIZED)) {
%>
<script language="javascript">
location.href('<portlet:actionURL windowState="Normal" />');
</script>
<%
} else {
%>
<table class="noborder" align="center">
<tbody>

<tr>
<td valign="bottom">
<IFRAME src='blank.html' name='exchangeIndicesModule' id='exchangeIndicesModule' width='170' height='248' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'></IFRAME>
</td>
</tr>

<tr>
<td>
<jsp:include page="QuoteLookup.jsp" flush="true"/>
</td>
</tr>

<tr>
<td>
<a href="<portlet:actionURL windowState="Maximized"><portlet:param name='content_dm' value='complete'/></portlet:actionURL>">
Click here for the complete market summary</a>
</td>
</tr>

</tbody>
</table>
<%
}
%>
</div>
<script language="javascript">
document.exchangeIndicesModule.location="<%= exIndModuleURL %>";
</script>
 
I suppose this goes to show that giving good details to start with can save headaches... the error is not that 'document is undefined', but that 'document[!].exchangeIndicesModule[/!] is undefined'.

So, in your case, perhaps try one of these:

Code:
document.getElementById('exchangeIndicesModule').
document.frames['exchangeIndicesModule'].

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
As a side note, I'd check the dangerous combination of double and single quotes you have

Code:
<a href="<portlet:actionURL windowState="Maximized"><portlet:param name='content_dm' value='complete'/></portlet:actionURL>">

Cheers,
Dian
 
along what billyray was saying:

document.getelementbyid(IFRAME).src = url;

should button you up, if you're still having problems, on firefox, and doing cross development i HIGHLY recommend adding a plugin named "firebug" it'll let you step line by line through the JS and find the exact location of the error.

if it still pukes on document.getelement....
try : window.body.geteleme...
or : window.document.geteleme...


[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Hi

DreX said:
document.getelementbyid(IFRAME).src = url;
Please note that JavaScript is case sensitive. There is no getelementbyid method, only [tt]getElementById[/tt].

While you mentioned FireBug, you can easily try this out :
Code:
[blue]>>> typeof document.getelementbyid[/blue]
[red]"undefined"[/red]
[blue]>>> typeof document.getElementById[/blue]
[red]"function"[/red]


Feherke.
 
i do understand it is case sensitive, i was typing a quick response in order ot be of assistnace, as this forum is supposedly for IT professionals, i would figure my collegues out there know to correct the case sensitivity, and to replace out the IFRAME in the call to the respective title, but thank you much for the lesson on proper LeTtErInG

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
even give u a star for it

[2thumbsup]

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
i do understand it is case sensitive, i was typing a quick response in order ot be of assistnace, as this forum is supposedly for IT professionals, i would figure my collegues out there know to correct the case sensitivity

But you wrongly assume everyone here (1 million+ members) know JavaScript is case-sensitive. Normally people are asking because they don't know something...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi

DreX said:
i was typing a quick response in order ot be of assistnace
No need to type so fast. :) The OP not signed in since Thu, Mar 26, 2009.
DreX said:
as this forum is supposedly for IT professionals, i would figure my collegues out there know to correct the case sensitivity
Yes, but many IT professionals are not JavaScript professionals too. Someone used to work for years with a case insensitive language can be easily confused by such code sample.

Feherke.
 
Whoa, whoa gentlemen. I greatly appreciate all of the assistance. You were all right. getElementById and getframes both worked. It was the .location property that was causing the problem in Firefox.

While I agree with DreXor that someone writing scripts should know camel case. I work with 9 experienced Java developers that wrote all this malfunctioning javascript, and I've seen some pretty sloppy code. Someone like myself, who is inexperenced, can come thru later and copy those mistakes.

I would like to say that I am very impressed by the professional courtesy that I have encountered in these fourms. I have always received timely and insightful suggestions. For developers to take time out of their busy schedules to assist other developers is both impressive and promising for the future of our industries. Thank you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top