473,396 Members | 1,886 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.

How to use the file name of a web page inside the code?

16
The following code is in a file called Dog_features.htm

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('MyDiv').innerHTML = "<iframe src='Dog_Page1.htm'></iframe>";
  2.  
Is there a way to replace the word Dog in the code with a variable which resolves to the first word in the page's file name? e.g.

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('MyDiv').innerHTML = "<iframe src='Animal_Page1.htm'></iframe>";
  2.  
So if the 2nd snippet is in a file called 'Cat_features.htm' then the file 'Cat_Page1.htm' would be loaded into the iframe.
Jul 22 '10 #1
8 1461
tur130
16
Ok I got this far on my own...

Expand|Select|Wrap|Line Numbers
  1. function getFileNameAnimal() {
  2. //this gets the full url
  3. var url = document.location.href;
  4. //this removes the url end after "_"
  5. url = url.substring(0, (url.indexOf("_") == -1) ? url.length : url.indexOf("_"));
  6. //this removes everything before the last slash in the path
  7. url = url.substring(url.lastIndexOf("/") + 1, url.length);
  8. //return
  9. return url;
  10. }
  11.  
Will get the bit of the file name I need...almost there...
Jul 22 '10 #2
tur130
16
Solved it - for future ref posting here...

Expand|Select|Wrap|Line Numbers
  1. <div id="MyDiv">This Text gets replaced with the appropriate animal_Page1.htm file based on the file name of this file</div>  
  2.  
  3. <script>
  4. function getPage1() {
  5. var Animal = getFileNameAnimal();
  6. document.getElementById('MyDiv').innerHTML = "<iframe src='"+Animal+"_Page1.htm'></iframe>";
  7. }
  8. </script>                 
  9.  
  10. <input id="btn3" value="Get Page 1" 
  11.                  onclick="getPage1()" type="button"/>
  12.  
This code uses the function I posted earlier.
Jul 22 '10 #3
drhowarddrfine
7,435 Expert 4TB
You should ask javascript questions on the javascript board.
Jul 22 '10 #4
tur130
16
@drhowarddrfine
Will try harder to get the right board next time.

That said my requirement is actually javascript agnostic. If there is a way to do this without javascript that would be even better.
Jul 22 '10 #5
TheServant
1,168 Expert 1GB
@tur130
There is, but then you need server side script (like PHP for example). If you are using pure HTML/CSS, there is no execution, only display. What you are asking for is something only a script can achieve and then you can choose server side or client side.
Jul 23 '10 #6
tur130
16
I'll bow to your experience here.

That said I've seen some clever tricks with CSS that make it 'look' like some script is at work where in fact there isn't. I guess my point is that a solution can come from an unexpected angle and posting in a particular technology board kind of implies that you want the solution to use that particular technology.

Perhaps there should be a technology agnostic question board? Where you can just post your requirements and constraints and then see if you can get some inspired ideas that otherwise might not have been realized.

On this subject - is there any other technology (other than HTML, JS, CSS) hidden in bowers, perhaps not commonly used any more that is worth reading up on?
Jul 23 '10 #7
TheServant
1,168 Expert 1GB
@tur130
No need to bow, we're all students.

I am not aware of any "hidden" technology. Browsers are actually very simple, they display what they're sent. More advanced browsers can deal with client side scripting (javascript, AJAX), but generally they're not designed to do much more. That is going to change very soon with "the cloud" but for now Bytes generally has all the technologies worth learning. Having said that, I believe ASP can do some things that others can't, simply because it's made from Microsoft.

With regards to the technology agnostic board: We kinda do have one for Software development, but it's not used in website building. I imagine if you get to the stage of being able to switch between all technologies, you won't need to ask a "technology agnostic question" because you will know which language is best for that situation. However, if you are like most, you will have your preferences, and a little bit of some others to fill in the gaps your preferences cannot do. What I believe Bytes prefers to go for is users to have some idea on languages before they get here. Obviously we can point you to a more appropriate language if you are clearly in the wrong language, but if you don't even know what the different languages are (or a few in particular), you are not in any good position to ask an intelligible question anyway.

I have gone to the Java forums and asked a silly, uneducated question like: Should I use Java or C++ for THIS. The response was very limited, because the truth is, most languages can do most things, and it comes down to your experience, background, future plans, time available, etc. These cannot be captured in a simple post to ask for a technology agnostic question.

So to sum up, while I am not opposed to the idea, I do not seeing it being greatly helpful, and could result in too many "general/uneducated questions".

[/rant]
Jul 23 '10 #8
tur130
16
You guys are very responsive and know your stuff - cheers.
Jul 23 '10 #9

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

Similar topics

4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
1
by: Marek Prerovsky | last post by:
Hello, I implemented some Python functions in my C/C++ code. I need to know the Python source file name and line number of just executed Python command which calls my function. How can I get...
1
by: Ann Leland | last post by:
I have been using session variables to pass a user name from one ASP page to another inside framesets for 9 months and it stopped working this week. I have made no code changes but there was a...
1
by: Marcin Okraszewski | last post by:
Hi, I would like to include one page inside an other page, almost like a IFRAME does it. The problem is that I would like the included part to occupy as much space as it needs, so it would be...
21
by: ryanmhuc | last post by:
I know the subject might be confusing. I am no beginner with javascript but I haven't been able to figure out how to get the javascript file name from code inside the file. So you have an HTML...
1
by: Rukmal Fernando | last post by:
Hi all, I have a file retrieved from a database and I want to return it over a web page. I currently have an ASPX page (Download.aspx) with code similar to the following in Page_Load(): ...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
8
by: Dave G | last post by:
I know this is an old favourite but I can't find a simple answer to a simple question. I'm trying to run this: shell("c:\program files\pkware\pkzipc\pkzipc.exe -ext " & myPath & myZIPFile & "...
10
by: Ben Finney | last post by:
Howdy all, Question: I have Python modules named without '.py' as the extension, and I'd like to be able to import them. How can I do that? Background: On Unix, I write programs intended to...
2
by: Firepony | last post by:
I was wondering if anyone could tell me how i can use a vairable as a file name such as. #include<iostream> #include<fstream> ifstream file; string file = "test.dat"; ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.