473,385 Members | 1,347 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.

How to use javascript to change URL from page within OBJECT (IE)

6
I have an embedded html page loaded via the object tag on my main page. I'm working in XHTML strict so using iFrame is out. I call the embedded page using this:

[HTML]<object data="mypage.html" type="text/html"></object>[/HTML]

Now the referenced page loads just fine in the browsers I am testing with (IE 6&7/FF/ Safari). My problem is I have a simpe link on the embedded page that when clicked should change the main page to whatever URL the link points to. I've done this in the past with iframes using [HTML]<a onclick="window.top.location='anotherpage.html';"> Go Here</a>[/HTML] so I thought this might work using OBJECT like it does using iframe.

Well it doesn't work entirely. It works just fine in firefox, but stupid IE only loads the new URL within the object element its self, not the whole window like i want. I've tried using window.parent, window.self, so forth and so on but no luck. Any advice? It would also be cool if there was a way to call a function declared in the main page from the embedded page. I haven't found a way to do that either...

Thanks in advance!

~Brian
Mar 12 '08 #1
4 3359
hsriat
1,654 Expert 1GB
Did you try this..
[html]<a href="anotherpage.html" target="_top">Go Here</a>[/html]

Or just simply try without any target.
Mar 23 '08 #2
thig95
6
Did you try this..
[html]<a href="anotherpage.html" target="_top">Go Here</a>[/html]

Or just simply try without any target.
Hey thanks for the reply! Yes, that was one of the first things I tried to do...that would work just fine if I was embedding an iframe, as i've used that before. For some reason the script's behavior seems to act different when using OBJECT instead of IFRAME. I wonder if the parent/child association gets mixed up in IE.

Of course this works in FireFox and mozilla based browers, just not IE....

I'm at a standstill here, as i've yet to find a way around this. I guess i could make an exception and code the page in transitional instead of strict, but i would really like to avoid doing that.

~Brian
Apr 2 '08 #3
mrhoo
428 256MB
I don't remember IE6, but I can read and write to window.top and window.top.location from an embedded (type=text/html) object in IE7, same as firefox.

I do it with a script, and not inline, though I don't know why that would make a difference.

part of an onload function for the object page:

Expand|Select|Wrap|Line Numbers
  1. onload=function(){
  2.     var WT= window.top;
  3.     if(self!= WT){
  4.         var A= document.links, i= 0,tem;
  5.         while(A[i]){
  6.             tem= A[i++];
  7.             tem.onclick= function(e){
  8.                 e= window.event || e;
  9.                 e= e.target || e.srcElement;
  10.                 WT.location= e.href;
  11.             }
  12.         }
  13.     }
  14. }
Apr 2 '08 #4
thig95
6
Thanks so much for your reply. I'm just having a hard time understanding how you are able to get this to work and i'm not...I am also working in IE 7 but still haven't had any luck even after trying the code you posted.

Maybe you could help explain this...I put this simple code into the embedded page to execute when it is loaded:

Expand|Select|Wrap|Line Numbers
  1. alert(window.top.location);
  2. alert(window.self.location);
  3.  
In IE, the code alerts the location of the topmost page for .self and .top...this only happens in IE, whereas firefox and opera alert the location of the topmost page and the embedded page seperately.

So going back to the code you suggested previously, the line

Expand|Select|Wrap|Line Numbers
  1.  if (self != WT) 
this statement is never true because window.self always seems to be equal to window.top no matter what I try to do...

I'm sorry if maybe i'm just missing something. Any thoughts?
Apr 3 '08 #5

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

Similar topics

1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...

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.