Link to home
Start Free TrialLog in
Avatar of KCTechNet
KCTechNetFlag for United States of America

asked on

jump to section of another page

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?
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rob
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.
Yeah like I said up there ^^^^^^^^^^^  the answer is No
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
Avatar of KCTechNet

ASKER

I will try it out today and let you know...
Just realized that they didn't put an ID on the div,so I can't try the code, right?
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.
HMMMM......................

Sounds like something I said  ^^^^^^^^^^^^^^^^  up there 3 days ago.
@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
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.
thanks
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.
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.