jQuery if url hash, click event/activate javascript

前端 未结 3 1480
悲哀的现实
悲哀的现实 2021-01-01 01:11

So from the home page, i have a link that goes to a products listing page. The product page has expand/collapse divs.

I need the appropriate div to expand depending

3条回答
  •  不思量自难忘°
    2021-01-01 01:41

    The answers suggested here are valid, but...

    Be extremely careful when using the window.location.hash as it is in a jQuery selector because this could lead to a XSS vulnerability. $() can also create an HTML element and with a carefully constructed hash value, someone could execute arbitrary JavaScript code.

    For example

    http://my-website.com/about#'>

    If my-websites.com/about page uses the window.location.hash inside a jQuery selector, that onerror code would end up getting executed.

提交回复
热议问题