Solved

How do I open a dynamic HTML page at an anchor within the page?

Posted on 2014-09-05
6
338 Views
Last Modified: 2014-09-07
My program outputs a dynamic HTML page from a server. Is there a way to make the page open at an anchor within the page rather than at the top of the page?

Example: An HTML page is created on the fly with an anchor tag <a id="target"></a> 2/3 of the way down the page. The page is written (as always) to stdout. How do I get that page to open at the target?

With static pages, it is easy -- <a href="www.MyServer.com/MyPage.asp#target">Click here</a>. When writing dynamic pages, how ???????????
0
Comment
Question by:StMike38
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:rwniceing
ID: 40305902
Read this anchor tag tutorial link at http://www.w3schools.com/tags/tag_a.asp

and try <a href="www.MyServer.com/MyPage.asp#target" target="_top">Click here</a>

Is it what your need ?
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 40305910
You could probably inject some javascript to open the page (to the imbedded anchor) once it's been generated.  You would need a flag of some sort to make sure the javascript only fired once.

There's also window.location in javascript, which you might be able to use to scroll to an anchor location on the page.
0
 

Author Comment

by:StMike38
ID: 40306144
To rwniceing: When creating a dynamic page, there is no one to click a link. The target is not the top; it's well below.

To paulmacd: I have written and am writing (too many tens of thousands of lines of) C++. The problem with Javascript is that I cannot maintain it.

I have implemented a temporary solution -- injecting a link visible near the top of the page, so the user has to click it to be taken to the desired point. If interested, you can see that solution as follows:
[1] Browse to http://www.marpx.com/shake/
[2] Click on "Launch research index"
[3] Enter something in the search box, for example: Ophelia water [without quotes]
[4] Click the "Expand" logo in the lower left.
[5] Note the link "Highlighted result" near the top. Click on it.
[6] You are taken to the result well down the page.

I would prefer to make step 5 unnecessary by having the page open at the paragraph containing water and Ophelia 4 words apart.

StMike38
0
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!

 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 500 total points
ID: 40306252
There's nothing to maintain.  As you build the page, write out a body tag that includes an onload event...
     <body onload="window.location.hash='anchor';">

...then, wherever you want to page to jump to, insert an anchor tag...
     <a name="anchor">

...and you should be all set
0
 

Author Comment

by:StMike38
ID: 40307617
To paulmacd: Modifying the body tag works both in the server program and in a PC-based CHtmlView equivalent program. In both cases, the page opens very nicely at the anchor point.

Thank you very much for a neat and elegant solution. You have been most helpful.

StMike38
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 40308978
I'm glad the solution works for you, and am very happy to have been of service.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't get cursor to change 3 16
Making Table Thru ASP Response.write 5 21
Error building VS2105 solution from repository 1 39
Capture Perfect Software 3 32
Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question