/    Sign up×
Community /Pin to ProfileBookmark

Loses place in main doc

I have a main document that has several links throughout the text that a reader may click on to open other related sub-documents. The sub-docs are opened into their own much smaller window using href calls to a javascript function.

If clicking a link located deep within the main document, the sub-doc gets opened just fine, but the view of the main document relocates to the top. Thus, the reader would lose his/her place.

[B]Would you know how to maintain the location in the main document once a link is clicked? [/B]?

[U][B]Sample HTML Links:[/B][/U]
<p style=”text-indent: 1%”>
[INDENT]<a href=”#” onclick=”goHere(‘/docName1.html’, ‘Doc1’)” class=”linksimple”>How Scored</a>
&nbsp;&nbsp;
[/INDENT]
[INDENT]<a href=”#” onclick=”goHere(‘/docName2.html’, ‘Doc2’)” class=”linksimple”>Strategy</a>
&nbsp;&nbsp;
[/INDENT]
[INDENT]<a href=”#” onclick=”goHere(‘/docName3.html’, ‘Doc3’)” class=”linksimple”>Example Table</a>
&nbsp;&nbsp;
[/INDENT]
</p>

[U][B]Sample of Script:[/B][/U]
function goHere(here, name) {
window.open(here,name,”location=no, scrollbars=yes, toolbar= no, menubar=no, status=yes, resizable = yes, height=400, width=500″);
}

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoSep 15.2008 — One way is to use anchors. When the user clicks the link (anchor) to open the window, then the window opens and the anchor on the main page is called, thus keeping the focus on that part of the document. There are other ways, but that is probably the simplest.
Copy linkTweet thisAlerts:
@Logic_AliSep 15.2008 — The simplest fix for what you have in place is simply to add [CODE]return false;[/CODE]at the end of the [I]goHere[/I] function:
[CODE]function goHere(here, name) {
window.open(here,name,"location=no, scrollbars=yes, toolbar= no, menubar=no, status=yes, resizable = yes, height=400, width=500");
[B]return false;[/B]}[/CODE]
then add return at the start of each onclick handler, i.e.:[CODE]<a href="#" onclick="return goHere('/docName3.html', 'Doc3')" class="linksimple">[/CODE]
Copy linkTweet thisAlerts:
@Donna_JSDauthorSep 16.2008 — It works great. Thank you.

While I realize you probably pulled this out of your hat of experience, what do you use as technical reference? ?
Copy linkTweet thisAlerts:
@FangSep 16.2008 — Don't misuse the anchor&lt;a href="/docName3.html" onclick="return goHere(this.href, 'Doc3')" class="linksimple"&gt;
http://developer.mozilla.org/En/DOM/Window.open
Copy linkTweet thisAlerts:
@Donna_JSDauthorSep 17.2008 — I am not sure I understand what you are trying to tell me Fang. I can appreciate that you thought it important enough to post the warning.

Could you explain? R-U referring to konithomimo's solution?
Copy linkTweet thisAlerts:
@konithomimoSep 17.2008 — My method is part of what Logic Ali posted. By anchor Fang means href="#". Anchors should be used to navigate to part of a page. The method Logic posted will not cause any problems, but it is not the reason anchors exist in HTML/JS.
Copy linkTweet thisAlerts:
@FangSep 17.2008 — &lt;a href="/docName3.html" onclick="return goHere(this.href, 'Doc3')" class="linksimple"&gt;
This way the JavaScript popup window will open as expected and for those with JavaScript disabled the link will still work.

http://htmldog.com/guides/htmladvanced/links/
×

Success!

Help @Donna_JSD spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...