views:

181

answers:

1

I've got a window.location function that redirects to a site that is not programmed by me. When the window is relocated I need it to focus on a specific div tag (with an id) within that page. Is there a way for me to do that if the page is not mine and I do not have access to the code?

UPDATE so I've got this now and it's working...

     window.location = 'http://www.mozilla.com/en-US/firefox/all-older.html#en-US';

UPDATE

I don't suppose it would be too much to see if I could act upon this div using the window.location function... to elaborate, is there a way for me not only to focus on a specific div but also highlight that div?

+2  A: 

Sure, use the element's ID as an anchor in the URL: http://external.test.com/page.html#div-tag-id. Element IDs work just as well as <a name="..."></a> tags nowadays.

Edit: You can scroll to the div but you can't highlight it. Security restrictions prevent code from different domains from interacting with each other. If you were allowed to "do things" to another domain's page you could, for instance:

  1. Open Facebook in an iframe, hoping that the user is already logged in.
  2. Fill out a message by finding the appropriate text boxes and doing input.value = "...";.
  3. Automatically submit the form via form.submit();.
  4. Voila, instant spam!

That's just an example of the dangers cross-site scripting would present. So for that reason browsers won't let you manipulate another page, not even to just change the background color on an element.

John Kugelman
please see OP update
sadmicrowave
John is correct, but I think you misunderstood his example URL. Please see my comment to the OP.
Matt Sach