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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thig95
    New Member
    • Nov 2007
    • 6

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

    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.ht ml" 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.htm l';">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
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Did you try this..
    [html]<a href="anotherpa ge.html" target="_top">G o Here</a>[/html]

    Or just simply try without any target.

    Comment

    • thig95
      New Member
      • Nov 2007
      • 6

      #3
      Originally posted by hsriat
      Did you try this..
      [html]<a href="anotherpa ge.html" target="_top">G o 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

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        I don't remember IE6, but I can read and write to window.top and window.top.loca tion 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:

        [CODE=javascript]
        onload=function (){
        var WT= window.top;
        if(self!= WT){
        var A= document.links, i= 0,tem;
        while(A[i]){
        tem= A[i++];
        tem.onclick= function(e){
        e= window.event || e;
        e= e.target || e.srcElement;
        WT.location= e.href;
        }
        }
        }
        }[/CODE]

        Comment

        • thig95
          New Member
          • Nov 2007
          • 6

          #5
          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:

          [CODE=javascript]
          alert(window.to p.location);
          alert(window.se lf.location);
          [/CODE]
          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

          [CODE=javascript] if (self != WT) [/CODE]
          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?

          Comment

          Working...