By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,353 Members | 637 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,353 IT Pros & Developers. It's quick & easy.

Javascript - Access By URL: show layer of hidden content only when on certain URL

P: 5
Hello,

I hope somebody can help me I have been at this for hours. I am new to JavaScript.

I need a script to show a layer of hidden content only when on a certain URL. I have searched and found nothing, is this possible to do ?

Example:

http://mydomain.com/index.php?1 = content = hidden
http://mydomain.com/index.php?2 = content = show

(The content is basically a table of text)

I did find the following script (below) which pulls the current URL from the browser. but have no clue how to do this

<script language="JavaScript">
Expand|Select|Wrap|Line Numbers
  1.         var URL = unescape(location.href)    // get current URL in plain ASCII
  2.     var xstart = URL.lastIndexOf("") + 1
  3.     var xend = URL.length
  4.     var hereName = URL.substring(xstart,xend)
  5.     var herePath = URL.substring(0,xstart)
  6.     document.write("The name of the current file is: " + hereName)
  7.     document.write("The path of the current file is: " + herePath)
  8.  
</script>

Any help would be great!
May 7 '06 #1
Share this Question
Share on Google+
2 Replies

P: 4
The solution is a bit simpler in php, and it seems that is what the extension of the pages is anyway.

Try putting the table html in a separate file named, say, "hidden.inc". Then add the following bit of code in place of the table in the main file:

[PHP]<?php if($_GET['content'] == "hidden") include "hidden.inc"; ?>[/PHP]

There are numerous ways to do this, but this is probably the simpest and most straightforward (coming from someone who loves PHP, of course).

The extension of the index file must be .php for this to work. Then the url http://www.mydomain.com/index.php?content=hidden will show the content and everything else won't.

I hope this helps.

Elijah
May 7 '06 #2

acoder
Expert Mod 15k+
P: 16,027
Can also be done with JavaScript. Use location.search to get the search string. If it equals "?2", show the content, e.g.
Expand|Select|Wrap|Line Numbers
  1. var search = location.search;
  2. if (search == "?2") {
  3.     var layer = document.getElementById("layer"); // replace 'layer' with id of layer.
  4.     layer.style.display = "block";
  5. }
Call this onload.
Jun 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.