/    Sign up×
Community /Pin to ProfileBookmark

variable for hyperlink

I have a question about some HTML programming im doing and what kind of file I should create.

I need to make a dynamic variable that makes a hyperlink. I need to have a text file which will contain an ip which is updated every day by another script.

What I need is for a variable on each page, to assign it’s self to an ip in the text file. Then, throughout the page, links will look as follows.

a href = “http://<variable ip>/a_page.txt”> a page </a>

This does not work as far as I know. So I would like to know some solution to store the variable from the text file and incorporate it into the links on the page. This will be much easier than changing the ip every time in each file about 20 links a piece.

Thanks for your expert help ?

to post a comment
HTML

7 Comments(s)

Copy linkTweet thisAlerts:
@olafFeb 27.2004 — you should read some serverside articles about file functions
Copy linkTweet thisAlerts:
@TheBearMayFeb 27.2004 — It can be done with a little JS trickery and a hidden iframe.

First you need to define your links similiar to:

[code=php]<a href=# onclick="gotoDynLink()">Dynamic Link</a>[/code]

Second include something like this in your body:

[code=php]<iframe id="hiddenFrame" style="display:none" src="linkSrc.txt"></iframe>[/code]

Then up in the head area place something like:
[code=php]
<script type="text/javascript">
function gotoDynLink(){
window.open(hiddenFrame.document.documentElement.innerText);
}
</script>[/code]


Finally create your text file.....
Copy linkTweet thisAlerts:
@VladdyFeb 27.2004 — Javascript is certainly NOT the right tool for the task.

First, you do not need to update all your links: use relative URIs for the links within your document then the only variable you need to update is a BASE element definition in your header:

http://www.w3.org/TR/html4/struct/links.html#edef-BASE

If you would like to pull this definition from a single file use Server Side Includes:

<!-- #Include virtual="ipfile.txt" --> (that is for Apache server - ASP/IIS syntax is similar)

Where ipfile.txt contains the singe line of BASE declaration.
Copy linkTweet thisAlerts:
@modemideauthorFeb 27.2004 — actually the thing is I need it to be http://ipadress/whatever..

b/c it is not locally hosted, the pages are to bring up data from somewhere else. but the ip address changes, thus to make the switch easier I need something like this. Consider it almost like a mirror.

Don't worry I'm not using this to leech off of a site ;-) ... just something my friend and I are setting up.

the problem with the post below mine is ... I still have to redefine all the ip addresses. (I appreciate the thought tho). What I need is something similar to this:

//Declare variable for ip address

ipAdd = GetIpFromTextfile()

<a href = "http://ipAdd/somefolder/somehtml.html> a link</a>

<a href = "http://ipAdd/somefolder/somehtml.html> another link</a>

etc...

I have too many links which is the reason why I would liek to do something like this. so instead of going through each HTML file, I can simply have my script change the .txt file and the links on each HTML page (keep in mind more than 10) will automatically change because the variable references the text file for the ip address.

I don't mind changing the format of all the pages to .php or .dhtml or what have you. So keep that in mind if you reply.

Thanks again :-)
Copy linkTweet thisAlerts:
@VladdyFeb 27.2004 — Does not change the validity of my answer.
Copy linkTweet thisAlerts:
@TheBearMayFeb 27.2004 — You're going to have to change the links one time regardless. After doing that you could change the function to:
[code=php]
<script type="text/javascript">
function gotoDynLink(){
window.open("http://"+hiddenFrame.document.documentElement.innerText+"theRemainder of the string");
}
</script>
[/code]

and get what it appears you're asking for. Then if the address changes, it's just a matter of changing the text file from there on out.
Copy linkTweet thisAlerts:
@modemideauthorFeb 28.2004 — Thnx bear, I'll try it now and see if it works. Looks functional tho ?

Ok .. here is what I ended up doing. I used javascript to open the window as bear showed me. However I made one change. I created a js file that looks like this:

var site_ip = "###.###.###.###"

then I used the <SCRIPT> operator on each page to include the site_ip.js file into each of the pages

and references the variable when i used java script to open the window.

Thanks for all your suggestions guys ;-)
×

Success!

Help @modemide spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...