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

iframe problem - null object error when changing url

Hi,

I've struggled with this for a while now, so I'm asking for help. I
am trying to click on a link in one page, have that link open up in a
new window, and set that newly opened window's ifram to a specific
url. Here is the code I'm using:

<html>
<head>

<script>
var myWindow;
function run(page1,framepage) {
myWindow=window.open(page1,'window');
myWindow.frames['winPanel'].location.href=framepage;
if (window.focus) {myWindow.focus()}
}
</script>

</head>
<body>
<a href="javascript:"
onClick="run('scroll.html','temp.html');">click4lo cal</a>
<a href="javascript:"
onClick="run('http://www.mysite.com/page_with_iframe.htm','http://www.mysite.com/page_to_go_in_iframe.htm;">click4remote</a>
</body>
</html>

The strange this is that the first link works just fine when I run it
locally, but the second link won't work when I put it on my server.
It opens up a page with the iframe, but I get the error "line: 10
character 2 'myWindow.iframes.winPanel.location is null or not an
object," so it doesn't load the url into the iframe.

I appreciate any help you can give me!

Jim
Jul 23 '05 #1
5 4175
Jim Marquardson wrote:
Hi,

I've struggled with this for a while now, so I'm asking for help. I
am trying to click on a link in one page, have that link open up in a
new window, and set that newly opened window's ifram to a specific
url. Here is the code I'm using:

<html>
<head>

<script>
var myWindow;
function run(page1,framepage) {
myWindow=window.open(page1,'window');
myWindow.frames['winPanel'].location.href=framepage;
if (window.focus) {myWindow.focus()}
}
</script>
Why not pass the src of the iframe?
myWindow=window.open(page1+"?pageWithIFrame.html", 'window')

Then parse the IFrame src from the location.search property of
pageWithIFrame.html

if(location.search && isFile(location.search.substring(1)){
document.frames['winPanel'].src=location.search.substring(1);
}
The "isFile(file") function needs to examine the query to see if it is a
proper candidate for the iframe.

Mick

</head>
<body>
<a href="javascript:"
onClick="run('scroll.html','temp.html');">click4lo cal</a>
<a href="javascript:"
onClick="run('http://www.mysite.com/page_with_iframe.htm','http://www.mysite.com/page_to_go_in_iframe.htm;">click4remote</a>
</body>
</html>

The strange this is that the first link works just fine when I run it
locally, but the second link won't work when I put it on my server.
It opens up a page with the iframe, but I get the error "line: 10
character 2 'myWindow.iframes.winPanel.location is null or not an
object," so it doesn't load the url into the iframe.

I appreciate any help you can give me!

Jim

Jul 23 '05 #2
> Why not pass the src of the iframe?
myWindow=window.open(page1+"?pageWithIFrame.html", 'window')

Then parse the IFrame src from the location.search property of
pageWithIFrame.html

if(location.search && isFile(location.search.substring(1)){
document.frames['winPanel'].src=location.search.substring(1);
}
The "isFile(file") function needs to examine the query to see if it is a
proper candidate for the iframe.

Mick


Thanks for the code. It opened up the new window, but it still didn't
load the right page in the iframe and now I am getting another error:
"Access is denied." I think this problem has to do with iframes
security, and I don't think there's an easy fix.

Jim
Jul 23 '05 #3
I worked some more at the problem, and I solved it with your code. It
took some more coding to make your solution work, but it ended up
being the best solution. I thought I'd post what I ended up doing.

A sample link would be <a
href="PageWithFrame.html?nonDefaultContent.html">L ink</a>

Then, the HTML file:

<html>
<head>
<script>
function writeFrame() {
page = "defaultContent.htm"; //the default page
if(location.search /*&& isFile(location.search.substring(1))*/) {
page = location.search.substring(1);
}
document.write("<iframe src=\"" + page + "\" id=\"myIframe\"
name=\"myIframe\" width=\"800\" scrolling=\"no\"
frameborder=\"0\"></iframe>\"");
}
</script>
</head>

<body>
This is the page. Content goes here.
<script>writeFrame();</script>
</body>
</html>

I had too many problems trying to change the src of the iframe on
loading (usually because the iframe hadn't completed loading), so I
decided to write out the correct src the first time. That way, I
don't have to worry about changing it.

Thanks for you help,

Jim
Jul 23 '05 #4
Instead of document.write statement, put the <iframe id=...
name=...></iframe> code into HTML directly - without a src argument.

after that code, run your script to give a src (better be location.href) for
instants: document.frames('name_of_the_iframe').location.hre f=...;

This way you will not meet any trouble.

ccton

--
www.vicdir.com
"Jim Marquardson" <ji*@marqorp.com>
I worked some more at the problem, and I solved it with your code. It
took some more coding to make your solution work, but it ended up
being the best solution. I thought I'd post what I ended up doing.

A sample link would be <a
href="PageWithFrame.html?nonDefaultContent.html">L ink</a>

Then, the HTML file:

<html>
<head>
<script>
function writeFrame() {
page = "defaultContent.htm"; //the default page
if(location.search /*&& isFile(location.search.substring(1))*/) {
page = location.search.substring(1);
}
document.write("<iframe src=\"" + page + "\" id=\"myIframe\"
name=\"myIframe\" width=\"800\" scrolling=\"no\"
frameborder=\"0\"></iframe>\"");
}
</script>
</head>

<body>
This is the page. Content goes here.
<script>writeFrame();</script>
</body>
</html>

I had too many problems trying to change the src of the iframe on
loading (usually because the iframe hadn't completed loading), so I
decided to write out the correct src the first time. That way, I
don't have to worry about changing it.

Thanks for you help,

Jim

Jul 23 '05 #5
CryingClinton wrote:
<snip>
after that code, run your script to give a src (better be
location.href) for instants:
document.frames('name_of_the_iframe').location.hre f=...;
Global - frames - collections are widely supported on browsers that
understand what a frame is. Referring to a - frames - collection as a
property of the document is not nearly as reliable (and more likely to
encounter cross-domain scripting restrictions).

Treating a - frames - collection as a function and calling it with a
parameter is a Microsoftism that is not widely supported on other
browsers, a bracket notation property accessor works fine on IE browsers
and all other browsers that support the - frames - collection.

Assigning a string value to the - location - property directly (instead
of its - href - property) is slightly more reliable as it also avoids
some cross-domain security restrictions).

The most reliable cross-browser method of navigating a named IFRAME is:-

frames['iframe_name'].location = 'url_string';

(but would be safest done in conjunction with testing to ensure that
the - frames - collection was implemented, that the property accessor
from the named IFRAME returned an object, and that that object
implemented a location object).
This way you will not meet any trouble.


So long as it never sees any browser but IE.

<snip>
I worked some more at the problem, ...

<snip>

Please do not top-post on comp.lang.javascript (see the FAQ).

Richard.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: HolaGoogle | last post by:
Hi, Sorrryy to ask such basic question but i do need your help! Here's what i'm trying to do: In my parent form i'm calling a my Iframe form to get certain value, then depending on that value...
4
by: Treetop | last post by:
I have code that works in IE but not Netscape 7+. This code allows me to have a list of links that bring up an image and description in an iframe. This works great in IE, however I have users...
7
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+...
1
by: Rhys | last post by:
I have a page which has an IFrame on it. The src of the IFrame is a page with a datagrid on it. The Datagrid has bound template columns. The columns of the datagrid pass the bound data value of...
5
by: Grzesiek | last post by:
Hi! I have created page which contains some menu buttons and <iframe> with sub-page. Each menu action on the master web site should change content of iframe (by changing src attribute). But how to...
14
by: Aaron Gray | last post by:
Hi, I want to access the properties of an IFrame but seem unable to get access to the IFrames document body. <html> <body> <iframe src="test.html" id="IFrame"></iframe> </body>
8
by: Henrik Stidsen | last post by:
I am trying to access a table in an iframe via javascript. It sounds easy - but it won´t work... The iframe is added to the document via someContainerElement.innerHTML = "<iframe...>", it has...
2
riptide2049
by: riptide2049 | last post by:
I really have a problem here. I have a code that is suppost to take the href of a link from the right class;value of a link maked toreturn false. the value is a Media file the file is sent to...
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.