We help IT Professionals succeed at work.

jump to section of another page

KCTechNet
KCTechNet asked
on
I need a link on my page that will open another page and jump to a certain section of that page.  The problem is I do not "own" this other page and can not add bookmarks or anything to this second page.  I do see that they have a 'div' that I can call by name from my page if that helps.

So is this possible?
Comment
Watch Question

Top Expert 2013
Commented:
Unless they have a name anchor you can target you are out of luck.  You cannot do anything with a div id. that would require scripting on the target page.

RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
I haven't tested this fully but in theory it should work

my_window = window.open("", "mywindow1", "status=1,width=350,height=150");

// div with id=div1
var mydiv = my_window.document.getElementById('div1');
mydiv.outerHTML = "<a name='myname'>my place in the document</a>" + mydiv.outerHTML;
my_window.location.hash="myname";

Open in new window

If you don't have access to the code, the answer is NO, you cannot do it.  The above code will single out the DIV, or something like it, but it won't jump the browser to that section at the top of the screen.  Also bear in mind that many versions of IE will not do this anyway.  i.e. they will jump to a section in the current page, but they won't jump to a section in a different page.  The IE browser will always load a new page at the top, regardless of any appended section marker.  I don't know exactly when M$ fixed this problem, if ever, but it has existed for a long time.
Top Expert 2013

Commented:
Yeah like I said up there ^^^^^^^^^^^  the answer is No
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
ummm i didn't have access to the code either and could do it....  insert an anchor tag and direct the page to that section

Author

Commented:
I will try it out today and let you know...

Author

Commented:
Just realized that they didn't put an ID on the div,so I can't try the code, right?
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
You could use selectors but unfortunately I stand corrected - I was using the "developer tools" to inspect the object at runtime and chrome allows the object to be traversed, however javascript is prevented from doing so because of security risks.
If you were to open a new page that is on the same domain as the one you launched it from then there is no question it will work.
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
Top Expert 2013

Commented:
HMMMM......................

Sounds like something I said  ^^^^^^^^^^^^^^^^  up there 3 days ago.
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
@COBOL - no one had yet said why this wasn't possible... in fact it is when on the same domain, which wouldn't require scripting on the target page
Top Expert 2013

Commented:
Too much information and you would not have had the fun of proving me right.  I've been away from the site for several years but if you go through my PAQ you will find that when I answer no or can't be done I'm right 99% of the time.  I don't take that position unless I have previously been through the exercise that you have just experienced.

I'm not trying to discourage attempts to find unique solutions, but in the question the user indicated clearly that they did not own the page, and you failed to consider that. So the why it does not work was implied in the response to the question which included the stated conditions.

Author

Commented:
thanks
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
My comments were not meant to discredit you in any way and I value you contribution as much as everyone else.  

My point was to explain why it would not work and not just state it.  I feel it's important to relate this information to the people asking the questions so that similar ones are not asked and the foundations of the problem are understood.
Top Expert 2013

Commented:
I very well might have provided more detail if you had not posted an untested theory. At that point, the best course was to see if some "outside the box" thinking was going to solve a previously unsolvable problem.  It was best to let the testing proceed and just wait and see.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.