473,804 Members | 3,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

16 New Member
The following code is in a file called Dog_features.ht m

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.h tm' then the file 'Cat_Page1.htm' would be loaded into the iframe.
Jul 22 '10 #1
8 1483
tur130
16 New Member
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 New Member
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 Recognized Expert Expert
You should ask javascript questions on the javascript board.
Jul 22 '10 #4
tur130
16 New Member
@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 Recognized Expert Top Contributor
@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 New Member
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 Recognized Expert Top Contributor
@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 New Member
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
1843
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 inside this module? Kind regards Andreas
1
5790
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 this information inside my C/C++ function? Thanks for any help. Marek
1
3115
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 "security update" installed on the server a few days ago but I can't find out exactly what it was. In the research I have done I found many articles on the subject of session variables in ASP pages inside framesets. From what I read a new...
1
8412
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 treaded as a DIV. In other words if it the included page exceeds a given size it would resize to to show full included page. Normally, the IFRAME would create scrollbars. I also tried with <object data="page.html" type="text/html">, but the result is...
21
18257
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 doc with script tag who's source is a javascript file. <HTML> <script src="javascript.js"></script> </HTML> Javascript.js
1
1356
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(): ... string file = Request;byte fileData = this.getFile(file); // this
18
2339
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 either manually enter the path and file name, or to browse for the file. I do not want that. Ideally, I want the user to click on a link, and the server side php app does the rest. Again, the file always has the same name, and is in the same place....
8
16448
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 & " " & myPath) I want to unzip a file who's path name is defined by the variable myPath and who's file name is defined by the variable myZIPFile, and
10
3780
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 be run as commands to a file with no extension. This allows other programs to use the command as an interface, and I can re-write the program in some other language
2
2349
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"; file.open(file.c_str())
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.