473,543 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,frame page) {
myWindow=window .open(page1,'wi ndow');
myWindow.frames['winPanel'].location.href= framepage;
if (window.focus) {myWindow.focus ()}
}
</script>

</head>
<body>
<a href="javascrip t:"
onClick="run('s croll.html','te mp.html');">cli ck4local</a>
<a href="javascrip t:"
onClick="run('h ttp://www.mysite.com/page_with_ifram e.htm','http://www.mysite.com/page_to_go_in_i frame.htm;">cli ck4remote</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.ifram es.winPanel.loc ation 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 4191
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,frame page) {
myWindow=window .open(page1,'wi ndow');
myWindow.frames['winPanel'].location.href= framepage;
if (window.focus) {myWindow.focus ()}
}
</script>
Why not pass the src of the iframe?
myWindow=window .open(page1+"?p ageWithIFrame.h tml",'window')

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

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

Mick

</head>
<body>
<a href="javascrip t:"
onClick="run('s croll.html','te mp.html');">cli ck4local</a>
<a href="javascrip t:"
onClick="run('h ttp://www.mysite.com/page_with_ifram e.htm','http://www.mysite.com/page_to_go_in_i frame.htm;">cli ck4remote</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.ifram es.winPanel.loc ation 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+"?p ageWithIFrame.h tml",'window')

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

if(location.sea rch && isFile(location .search.substri ng(1)){
document.frames['winPanel'].src=location.s earch.substring (1);
}
The "isFile(fil e") 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="PageWithF rame.html?nonDe faultContent.ht ml">Link</a>

Then, the HTML file:

<html>
<head>
<script>
function writeFrame() {
page = "defaultContent .htm"; //the default page
if(location.sea rch /*&& isFile(location .search.substri ng(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>writeFr ame();</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_i frame').locatio n.href=...;

This way you will not meet any trouble.

ccton

--
www.vicdir.com
"Jim Marquardson" <ji*@marqorp.co m>
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="PageWithF rame.html?nonDe faultContent.ht ml">Link</a>

Then, the HTML file:

<html>
<head>
<script>
function writeFrame() {
page = "defaultContent .htm"; //the default page
if(location.sea rch /*&& isFile(location .search.substri ng(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>writeFr ame();</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_i frame').locatio n.href=...;
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.javas cript (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
41177
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 enable or disable my submit button in my parent form without using any refresh/reload or submit button in my form. Looks realy simple but i don't...
4
1597
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 that are Netscape users. main page: var links=new Array();
7
4833
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+ doesn't seem to have the problem. I'm doing: this.iframe = document.createElement( 'iframe' ); this.iframe.id = this.id + 'wh';...
1
4688
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 each cell within it to my code behind file which generates the HTML to display the data in a formatted text box, some of which is editable, some of...
5
2250
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 detect when user has opened subpage not in master's <iframe> ? Is it possible to obtain reference to master's page from sub-page ? When I'm trying...
14
18263
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
52807
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 name and ID and its visible in my DOM explorer just as the table I need is it. The table is added from ASP.NET via Response.Write(). I have tried...
2
3268
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 quicktime or windows meida player depending on which plugin was found. after the plug in is found a iframe with the right player is created. here is the...
1
5792
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 inside the iFrame. For example.. first button contains google.com second button contains yahoo.com 3rd button contains hotmail.com if i...
0
7341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7584
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7677
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5258
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3385
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
952
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
626
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.