开发者

How to focus on a specific div using window.location = [x] in jquery

开发者 https://www.devze.com 2022-12-29 15:41 出处:网络
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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消