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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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