473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
2 4751
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
16,027 Expert Mod 8TB
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

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

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
5
by: Tudor Tihan | last post by:
Hi, This is my first post here, so please be kind. I have tryed to make a javascript html page loader by using an invisible <IFrame> and some javascript variable text passing between...
5
by: Skipp | last post by:
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...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.