Results 1 to 3 of 3

Thread: link to hidden div from different page using javaScript to show div

  1. #1
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default link to hidden div from different page using javaScript to show div

    Hi all,

    I used this code. Thanks codeexploiter. http://www.dynamicdrive.com/forums/s...on-mouse-click
    To hide/show divs on my page. It works well, except now I would like to create a link from another page to certain div (ex. div9). I tried
    <a href="myPageWithDivs.html" onClick="changeIt('div9');">
    But it doesn’t work it redirects to myPageWithDivs.html but with the first div shown not the div9.

    Thank you in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,165
    Thanks
    44
    Thanked 3,239 Times in 3,200 Posts
    Blog Entries
    12

    Default

    Assuming that:

    Code:
    changeIt('div9');
    will work if you are already on the myPageWithDivs.htm page, then simply add this script to the end of the myPageWithDivs.htm page, right before its closing </body> tag:

    Code:
    <script type="text/javascript">
    (function(){
    	function getQval(n) {
    		if(typeof n !== 'string'){
    			return null;
    		}
    		var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
    		return (m = r.exec(m))? unescape(m[1]) : null;
    	}
    	var div = getQval('div');
    	if(div){
    		changeIt(div);
    	}
    })();
    </script>
    Now a link from any other page may open div9 with a link like so:

    Code:
    <a href="myPageWithDivs.html?div=div9">Open Div 9 on myPageWithDivs.html</a>
    Same thing with other divs, just use - say, div8 or div2 instead of div9 there in the href.

    If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    it works....YAY
    Thank you very much jscheuer1

Similar Threads

  1. Replies: 1
    Last Post: 09-20-2010, 08:44 PM
  2. Replies: 1
    Last Post: 04-23-2010, 12:26 PM
  3. Replies: 0
    Last Post: 06-14-2007, 08:35 PM
  4. Replies: 0
    Last Post: 03-14-2007, 07:01 AM
  5. Replies: 1
    Last Post: 12-04-2006, 10:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •