[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1015
  • Last Modified:

location.href='#top' not working in firefox or ie9

Hi

Anyone got a simple workaround for <body onload="location.href='#top'" > to work in firefox

Ive a page loading within an iframe (controlled by another company/server) and my page position is starting on the middle of the page

thanks
0
louise_8
Asked:
louise_8
  • 9
  • 5
1 Solution
 
mvdeveloperCommented:
Can you use window.scrollTo(x-coord, y-coord) to position it?
0
 
louise_8Author Commented:
thanks for the suggestion
it doesnt work either...
0
 
louise_8Author Commented:
I tried window.scrollTo(0,0)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Kim WalkerWeb Programmer/TechnicianCommented:
The title of this question suggests that this is working properly in other browsers. Is this true? If not, the first issue is why the iFrame is scrolling to the middle of the page? Does the iFrame src URL contain an anchor? (Is there a hash mark (#) in the URL?) Also, is there an element with the id attribute set to "top" or an anchor with the name attribute set to "top". I haven't been able to determine what the browser is expected to do if you try to jump to a non-existent anchor.
0
 
louise_8Author Commented:
Thanks for the responses.

What I know for sure is it used to work when the code was written initially.

The iframe is managed by another company and its fine on the first page but when a link is clicked it opens at that position on the next page (ie at the position of the link on the first page)
iframe code:
<iframe id="cphMain_iframeSubscribe" name="iframeSubscribe" width="980px" height="2000px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://secure.scooppublishing.com.au/defaultif.html"></iframe>


http://www.scoop.com.au/subscribeOnline.aspx is the main page with the iframe, that opens our page https://secure.scooppublishing.com.au/defaultif.html

clicking on the first hyperlink Subscribe under the lifestyle series opens https://secure.scooppublishing.com.au/subscribe-packageif.asp?publication=WALifestyle

This has a div and onload function
<div id="top">
        &nbsp;
   </div><!--end top-->
This doesnt work within the iframe

Underneath this, I try using the #top in the link (the first individual magazine subscribe link)

https://secure.scooppublishing.com.au/subscribe-individualif.asp?publication=scoop#top 
- again this wont work within the iframe.

Does that give you clues?
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Actually this confuses me. When I look at your main page, the iFrame element is larger than the page it holds. So there is nothing to scroll. Are you expecting the main page to scroll down so that the "top" div inside the iFrame is at the top of the main window? The way you've coded this would cause the "top" div to be at the top of the iFrame. Which it is. If you want the main screen to scroll so that the iFrame is at the top of the main window, you'd need to add an onload event to the iFrame that sets the location of the main window to the id of the iFrame.
0
 
louise_8Author Commented:
thanks

I thought the iframe may be the issue however, when Im on the first page, if I click a link at the bottom of the screen it opens the next page at that location... the next page being within the iframe too

eg first page within the iframe
 https://secure.scooppublishing.com.au/defaultif.html clicking one of the subscribe links towards the bottom opens the next page (https://secure.scooppublishing.com.au/subscribe-individualif.asp?publication=scoop#top ) and positions it where the hyperlink was..

if the iframe doesnt load again (because both pages are within the iframe) is that not something I'd code in the main page eg https://secure.scooppublishing.com.au/subscribe-individualif.asp?publication=scoop#top 

Sorry, I really am stuck with this.  Ive increased the points too
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
I believe I've figure out what you're talking about. When you open the main page, you have to scroll down to get to the subscribe links toward the bottom. At this point the top of the iframe is off the top of the screen. Because the subscribe links are in the document inside the iframe, they have no control over the main window which holds the iframe. Therefore, an anchor to the top of the iframe document simply scrolls that document to the top of the iframe which is still off the top of the screen. In order to scroll the main page to the top of the iframe, the document inside the iframe would have to execute some javascript to instruct its parent to scroll when the subscribe links are clicked.

There is one other possibility. Even though the iframe does not support events according to HTML standards, all browsers seem to support the onload event on the iframe. You could try to add the following to your iframe tag:
onload="javascript: window.location='#cphMain_iframeSubscribe';"

Open in new window

However, this would probably cause the page to scroll to top of the iframe the first time the page is loaded.

Are you able to add javascript to the body of the pages inside the iframe? If so, you could add the follow to the body tags in those pages:
onload="javascript: window.parent.location='#cphMain_iframeSubscribe';"

Open in new window

This would cause the parent of the iframe to scroll to the top of the iframe when that page is loaded inside it.
0
 
louise_8Author Commented:
thanks, we're making progress...

Ive pasted onload="javascript: window.parent.location='#cphMain_iframeSubscribe';"
to the body of the pages inside the iframe.
What happens is while it jumps to the top of the page, it looks like it comes out of the iframe..

To clarify (as I know I may be confusing you)
the iframe page (which I do not control) is
http://www.scoop.com.au/subscribeOnline.aspx 

I've pasted the code onload="javascript: window.parent.location='#cphMain_iframeSubscribe';" into the pages inside the iframe
(clicked onto via the SUBSCRIBE hyperlins)
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Hmm...let's try:
onload="javascript: window.parent.location=window.parent.location.href+'#cphMain_iframeSubscribe';"

Open in new window

0
 
louise_8Author Commented:
unfortunately that opens in the same position too, ie where the hyperlink was on the previous page..
0
 
louise_8Author Commented:
Hi,

I've decided to quit my losses with this one and get the page to jump out of the iframe
onload="javascript: window.parent.location='#cphMain_iframeSubscribe';" makes the page jump out of the iframe however it also resubmits the page

so I guess my question now is, what code to I put inside the page so that the next page it opens is NOT in the iframe?
0
 
louise_8Author Commented:
Hi,
I've just made my page open out of the iframe.
Not the solution I was hoping for but a work around for now.

I didnt get the answer I wanted... can I still award points for effort?
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Sorry, louise_8, I got swamped with paying work which I'm sure is no consolation to you. There are a couple of alternatives to window.parent.location. There's window.parent.scrollTo(x,y) which is well documented. With it you can scroll to a specific x and y coordinate.

Then there's window.parent.document.getElementById("idname").scrollIntoView(true) which is only documented by Microsoft and Mozilla. This means it is supported by IE and Firefox but not necessarily by Safari, Chrome or Opera. I have not had time to determine whether these browsers support this non-standard method. You may want to try it out. It should scroll the top of the iframe to the top of the screen. You'd need to replace "idname" with the iframes id value.
0
 
louise_8Author Commented:
the iframe needed an update

Thanks for your help!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now