Redirect with click jQuery/Javascript

Asked

Viewed 818 times

1

I have a home page where when clicking on a menu item, redirect to another page and a click in a given service in a "accordion/accordion".

I have something like this:

var index = $(this).parent().attr('index');
        $(window.document.location).attr('href', 'index.php/servicos');
        setTimeout(function(){
            $('.'+ index +' img').click()
        }, 1000);

Don’t make it cute here rs.

But that’s not working. I gave a alert() and it seems to me that he gives the command inside the setTimeout BEFORE GOING TO ANOTHER PAGE.

  • Yes, it makes sense to run it before going to another page (as far as I know, it is impossible to execute a code on one page, redirect it to another and the code affects the next page, I may be wrong). Ideally, you pass on the information of which item was clicked to the next page. Passed on as cookie, GET, POST, Session Storage, Local Storage or in the server/client logic itself on the page in question.

  • You are using an iframe?

1 answer

1

This way it is not possible, because there is no way you can run the object of another page through the current page by javascript.

What I would advise is that you go through the URL

var index = $(this).parent().attr('index');
$(window.document.location).attr('href', 'index.php/servicos/'+index);

And on the services page in case, check if this get arrived, and if it has arrived, run: $('.'+ (o get que passou) +' img').click()

  • It still doesn’t work. 'index.php/servicos?index=' + index);

  • I thought I was using htaccess, which programming language is using?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.