How to link to the contents of another link?
August 4, 2008 9:24 AM   Subscribe

Is there a way for a hyperlink to simply 'parrot' whatever a second hyperlink might be pointing toward?

The overly simplified version of my situation would go something like this:

I have set up LinkA on Page1 to point toward a given file. I also need LinkB on Page2 to point toward this same file. The file however, and it's name, will change quite often.

Is there a way to set up LinkB to simply mimic/mirror/imitate whatever LinkA is pointing toward, so that all I ever need to do is to update the properties of LinkA?
posted by mathis23 to Computers & Internet (7 answers total)
 
Can you set up Page 3 to be an automatic redirect to the file, and then have LinkA and LinkB just point to that page? That way, LinkA and LinkB never need to be updated; to update the actual link to the file, you just have to change Page 3.
posted by inigo2 at 9:29 AM on August 4, 2008


Alternatively, use a function in an external javascript. Call this function from your two pages.
posted by le morte de bea arthur at 9:35 AM on August 4, 2008


Is it possible to give the link target (the file) a standard name, and then archive the files that no longer need to be referenced?

What tools are you using? Straight HTML? In any case this is going to be maintenance nightmare. You may want to look into server side scripting or an application platform.
posted by askmehow at 9:36 AM on August 4, 2008


Off the top of my head, the easiest way would be to use a basic PHP request -- so, say, make server/file.php refer to the file and update this link serverside. Other ways:

- Make all your pages php and use includes to stick the URL of the file there.

- If you must do it clientside you need javascript and some way of fetching the content of Page1 from Page2; either an AJAX server request or an empty iframe with Page1 in. Ugh
posted by katrielalex at 9:54 AM on August 4, 2008


Alternatively, use a function in an external javascript. Call this function from your two pages.

This by far the easiest and most practical solution. You already have some kind of "scripts.js" file included everywhere, right? Most decent sized websites do.
posted by drjimmy11 at 11:02 AM on August 4, 2008


PHP/Ajax/Javascript seems like total overkill to me. Some simpler ideas:

Symlink the file that LinkB would normally point to to LinkA's file. Symlink LinkA's file to the real file and update when needed.

Put a line in your .htaccess (or httpd.conf, if you run the whole server) along the lines of "Redirect temp LinkBPath LinkA".

Use mod_rewrite to change LinkB into LinkA when server sees a request. (Mod_rewrite is big, but doesn't have to be complex to use; some recipes are here.)
posted by hattifattener at 12:00 PM on August 4, 2008


I'm guessing that most people who don't live and breathe the command line are going to find it a lot easier to edit a .js file than to muck about with symbolic links or apache configuration files.

In your javascript file, which you edit as needed:
function foo() {window.location.href='http://your.constantly.changing.url';}

The links, which you never need to edit:
<a href="#" onclick="foo();">click</a>

That's all that would be required.

If you have a lot of these, it's probably worth looking at a serverside solution (or, better yet, find a way to stop renaming the file all the time) but for a quick one-off hack, this would work fine.
posted by ook at 12:46 PM on August 4, 2008


« Older Ruby + Graph Visualization   |   Teach me how to bean it up Newer »
This thread is closed to new comments.