4 Replies - 1179 Views - Last Post: 09 July 2013 - 06:02 AM

#1 Zel2008  Icon User is online

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 789
  • Joined: 06-January 09

Show div after redirect

Posted 08 July 2013 - 01:49 PM

Hi all,

I'm trying to redirect to a page, then show a specific div, like this:

$( '#about' ).click( function() {
	window.location = "index.html";
	$( '#div_welcome_text' ).hide();
	$( '#div_about' ).show();
	$( '#div_library' ).hide();
	$( '#div_contact' ).hide();
});



But when I get to the page, the div_welcome_text div is always shown, not div_about as it should be.

I know the reason for this is because when you use window.location, the page immediately redirects, so the commands to hide and show various divs aren't being called. But, I'm not sure of the right way to do this, and thus far Googling has proved fruitless.

Does anyone know of a reliable way to redirect to another page, and then show a particular div on that page? I'd appreciate any help.

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: Show div after redirect

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,028
  • Joined: 08-June 10

Re: Show div after redirect

Posted 08 July 2013 - 02:06 PM

you need to pass the ID of the div to show to the loading page. you can do that by using
- cookies
- URL hashes
- WebStorage
Was This Post Helpful? 1
  • +
  • -

#3 JMRKER  Icon User is online

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: Show div after redirect

Posted 08 July 2013 - 02:08 PM

View PostZel2008, on 08 July 2013 - 02:49 PM, said:

Hi all,

I'm trying to redirect to a page, then show a specific div, like this:

$( '#about' ).click( function() {
	window.location = "index.html";
	$( '#div_welcome_text' ).hide();
	$( '#div_about' ).show();
	$( '#div_library' ).hide();
	$( '#div_contact' ).hide();
});



But when I get to the page, the div_welcome_text div is always shown, not div_about as it should be.

I know the reason for this is because when you use window.location, the page immediately redirects, so the commands to hide and show various divs aren't being called. But, I'm not sure of the right way to do this, and thus far Googling has proved fruitless.

Does anyone know of a reliable way to redirect to another page, and then show a particular div on that page? I'd appreciate any help.

Thanks,
Zel2008


Send the div id in the redirection string.
For example: window.location = "index.html?divID=div_about";

Then in the index.html file, decode the ?divID-div_about portion
with a bit of command line "querystring" code. Easy to find with google or bing search
or even a search of this forum.

You could default to the "welcome" display if no redirection is necessary
and 'hide' all div sections except the passed ID value via the querystring logic.

Good Luck!
:)
Was This Post Helpful? 1
  • +
  • -

#4 Zel2008  Icon User is online

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 789
  • Joined: 06-January 09

Re: Show div after redirect

Posted 08 July 2013 - 02:11 PM

Thank you both for the ideas. :)

I ended up passing the id in a query string, so a combination of both of your ideas, and it works beautifully.

Thank you again!
Was This Post Helpful? 0
  • +
  • -

#5 JMRKER  Icon User is online

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: Show div after redirect

Posted 09 July 2013 - 06:02 AM

View PostZel2008, on 08 July 2013 - 03:11 PM, said:

Thank you both for the ideas. :)/>

I ended up passing the id in a query string, so a combination of both of your ideas, and it works beautifully.

Thank you again!

It's always a good idea to show an example of your solution for others to view and understand your problem.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1