Jump to content

Javascript help!


cip6791

Recommended Posts

Hello

 

I need a little help with something. The following links display 3 different divs on one page

 

<li id='textLinia' onclick="switchOptions('divLinia');" onmouseover="this.style.cursor = 'pointer';"><a href="#">Gama</a></li>

    <li id='textPiele' onclick="switchOptions('divPiele');" onmouseover="this.style.cursor = 'pointer';"><a href="#">Tip de piele</a></li>

    <li id='textTrat' onclick="switchOptions('divTrat');" onmouseover="this.style.cursor = 'pointer';"><a href="#">Tip de tratament</a></li>

 

I would like to set links from other pages to this page, but I want the links to link to the page with certain divs showing. How can this be done?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/109878-javascript-help/
Share on other sites

Try adding this in you HEAD tags:

 

<script type="text/javascript">
  window.onload = function ( ) {
    var matches = window.location.href.match(/#(.+?)$/);
    if(matches[1]){
      switchOptions(matches[1]);
    }
  }
</script>

 

then, when you link to the page, specify the 'content' with the anchor tag:

http://yourhost.com/path/to/page.html#divPiele

Link to comment
https://forums.phpfreaks.com/topic/109878-javascript-help/#findComment-563815
Share on other sites

cool ... thanks. it works ... but there is one thing that isn't quite right. when the page loads, the first div shows up for one second then the other div loads. can this be solved?

 

maybe it s just on my end ... check it out

 

http://pixeltennis.com/produse_cosmetice_roc.html#  <--- page with the three divs

 

http://pixeltennis.com/produse_html/sub_produse/roc_anti_cellulite.html <--- page with the links.

 

thanks for your help :)

 

 

Link to comment
https://forums.phpfreaks.com/topic/109878-javascript-help/#findComment-563821
Share on other sites

there isn't really a way around that....you could have all three hidden at first, then add an else to the onload where if no page is specified, the first is shown. but, if someone doesn't have javascript enabled, your site wouldn't show any content.

 

the other option is to do it with php...is php an option?

Link to comment
https://forums.phpfreaks.com/topic/109878-javascript-help/#findComment-563825
Share on other sites

take that code I had you put in the HEAD out and add it after the DIVs, like so:

 

<!--End gama !!! -->
<div id='divPiele' style="display:none; margin:0; height:340px;">
	<iframe frameborder="0" scrolling="no" src="produse_cosmetice_roc_piele.html" width="752" height="340"></iframe>
	</div> 
<div id='divTrat' style="display:none; margin:0; height:340px;">

	<iframe frameborder="0" scrolling="no" src="produse_cosmetice_roc_tratament.html" width="752" height="340"></iframe>
    </div> 
<!-- Set the page -->
    <script type="text/javascript">
      var matches = window.location.href.match(/#(.+?)$/);
      if(matches[1]) switchOptions(matches[1]);
    </script>

Link to comment
https://forums.phpfreaks.com/topic/109878-javascript-help/#findComment-563931
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.