简体   繁体   English

jQuery在页面重定向后执行鼠标单击

[英]Jquery execute mouse click after page redirect

I have a blog category page to which I want to re direct from my one of my blog posts page and I want to simulate mouse click events which tells which category do they belong to ie mouse click on the appropriate category in the blog page.I have achieved this on the blog page itself by means of jquery as follows, 我有一个博客类别页面 ,我想从我的一个博客帖子页面重定向到该类别页面,并且我想模拟鼠标单击事件,该事件表明它们属于哪个类别,即在博客页面中的适当类别上单击鼠标。通过jquery在博客页面本身上实现了以下目标,

function categoryNav(){
    window.onload() = function(){
    $('#item-0').click();
    $('#item-0-0').click();  
    };
 }

This works fine standalone on the page, but somehow I am not able to combine this with a href linking from my posts page ie after a link click from the page this function is executed, in that case where the click always gets executed first before the redirect. 这在页面上可以很好地独立运行,但是以某种方式,我无法将其与我的帖子页面上的href链接结合使用,即,在页面上单击链接后,将执行此功能,在这种情况下,始终始终在单击之前首先执行单击重定向。

I have tried window.onload,document.onload,document.ready but nothing seems to work correctly. 我已经尝试了window.onload,document.onload,document.ready,但是似乎没有任何正常工作。

What am I missing here? 我在这里想念什么?

On the first click, generate a url in the form www.myblog.com/?item-0 . 首次单击时,以www.myblog.com/?item-0的形式生成一个URL。 Then, on the target page (on DOM ready): 然后,在目标页面上(准备好DOM):

s = location.search;
        if(s != '') {
            var split = s.split('?');
            var cat = split[1];
            $('#' + cat + '').click();
        }

In the case above, you should trigger a click on #item-0 . 在上述情况下,您应该触发对#item-0的点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM