0

I have made a page with two divs that cover the whole page, but using them one by one, by hiding and showing them in request.

In other words, I only see the one page, and when clicking button 1 some things hide and some others show, when clicking button 2 the opposite.

My code:

$(function() {
    $('.boxes').click(function() {
        var e = $(this).attr('id');
        console.log(e);
        if(e == 'Button1') {
            $('#Div0').fadeIn(1000);
            $('#Div1').fadeOut(1000);
        }
        else if(e == 'Button2') {
            $('#Div0').fadeOut(1000);
            $('#Div1').fadeIn(1000);
        }
    });
});

That works fine.

Now the problem is that this is not my landing page. I have a landing (home) page where someone can click a button depending on what he wants to see. And I would like to load the page with those divs but with the correct div showing.

Basically what I need is the same process, but with the buttons (button1 & button2) being in a different page. So the click loads the page and runs the script to load (show) the correct Div.

I was thinking that if I can get a variable (variable e) to get value when button click and pass that variable to the next page when loaded that would work. Any idea on how to do that?

Or any idea on a different way to make this work?

Ninita
  • 1,209
  • 2
  • 19
  • 45
inasiopo
  • 55
  • 1
  • 10
  • Why can't you use `onload()` functionality ? http://stackoverflow.com/questions/4057236/how-to-add-onload-event-to-a-div-element – Ramkee May 30 '16 at 13:24

1 Answers1

0

You can actually grab the url on any given page by

var pathname = window.location.pathname; // Returns path only
var url      = window.location.href;     // Returns full URL

So what I would do is the following. On the landing page when you press the button pass a url with an extra parameter:

http://www.sdfsfsd.com/pages&divName=div1

On the other pages onload() function simply find the url and grab the divName. Then have both divs start as opacity:0 (css) and fade the correct div in.

Hope this helps!

Kyle Pastor
  • 489
  • 4
  • 8
  • Thank you for the response. I am trying to pass the url with the extra parameter but it won't work. It does not like it though...basically it gives me a "page not found"...Any ideas? – inasiopo May 30 '16 at 13:53
  • Could you give me an example of the url you are trying to pass? – Kyle Pastor May 31 '16 at 13:06