Q: location.href change & scrollBy problem

J

JF

Hi,

I need to change the location of the parent window and after
that scroll a little bit (because of "position:fixed" css buttons,
which obscure the title).

I have
window.opener.location.href = "newhreflabel";
window.opener.scrollBy(0, -25);

The newhreflabel may point to the same document or load
a new one (another chapter).

There is a problem is with timing, T think I need to
serialize those two instructions.

However, the window.opener.document.onload does not seem to
be trigered by href change. Is there any other way how to
do it - or I have ti all wrong?

Thanks
Josef
 
B

Bart Van der Donck

JF said:
I need to change the location of the parent window and after
that scroll a little bit (because of "position:fixed" css buttons,
which obscure the title).
I have
window.opener.location.href = "newhreflabel";
window.opener.scrollBy(0, -25);
The newhreflabel may point to the same document or load
a new one (another chapter).
There is a problem is with timing, T think I need to
serialize those two instructions.
However, the window.opener.document.onload does not seem to
be trigered by href change. Is there any other way how to
do it - or I have ti all wrong?

One approach could be to use anchors in your documents.

In your 'body.htm' file:

<a name="myanchor">...</a>

Then in your 'contents.htm' file:

window.opener.location.href = "body.htm#myanchor";

To reload to another document, you can use:

window.opener.location.href = "otherdocument.htm";
or
window.opener.location.href = "otherdocument.htm#otheranchor";

It 's not strictly necessary (though maybe better practice) that this
code goes inside <body onLoad="...">. Just putting it in a <script>
section should do it as well.

A change of XXX.location.href could be called from 'body.htm' as well
as from 'contents.htm' as long as they reside on the same domain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top