Log in

View Full Version : link to hidden div from different page using javaScript to show div



Jecika
08-06-2013, 03:54 PM
Hi all,

I used this code. Thanks codeexploiter. http://www.dynamicdrive.com/forums/showthread.php?16055-Change-Image-shown-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

jscheuer1
08-06-2013, 09:06 PM
Assuming that:


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:


<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:


<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.

Jecika
08-07-2013, 07:44 PM
Hi,

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