1

The code I want to run upon triggeting the redirect, is to go to another web page (or local html file, either is possible in this situation), however pass some javascript to run on that page, as that page works off embeding content in Iframes. This needs to be done to allow me to specify the content in the iframe upon redirect.

To put it simpler. How can I make it so when you go to website.com/about/, it redirects to website.com/ with the content for /about/ loaded in an iframe?

<head>
    <title> CodeBundle </title>
    <script>
        function home() {document.getElementById("loadedpage").src="home.html";}
        function about() {document.getElementById("loadedpage").src="about.html";}
        function reviews() {document.getElementById("loadedpage").src="reviews.html";}
        function tutorials() {document.getElementById("loadedpage").src="tutorials.html";}
        function blog() {document.getElementById("loadedpage").src="blog.html";}
</script>
</head>
<body>
    <header>
        <br><hr><font size=27><a onClick="home();">Code Bundle</a></font><br><hr>
        <div ALIGN=RIGHT>
            <font size=6> | <a onClick="about();">About</a> | <a     onClick="reviews();">Reviews</a> | <a onClick="tutorials();">Tutorials</a> | <a onClick="blog();">Blog<a> |</font> <hr>
        </div>
        <iframe id="loadedpage" src=home.html width=100% height=100% frameborder=0>Iframe Failed to Load</iframe>
    </header>
</body>
</body>    

this is my index.html for website.com/

I want to write a page so that when you go to website.com/about/ it redirects to website.com/ running the javascript function about(), so as to display the about page.

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
Code Bundle
  • 282
  • 1
  • 2
  • 14

2 Answers2

4

You will have to either pass some data using a query parameter or a fragment identifier.

See:

In either case you will have something present in the url and it will look like:

http://www.example.com/?page=about

or:

http://www.example.com/#about

or - this would be best:

http://www.example.com/#!/about

because it could let you make the website crawlable. See:


Now after reading your comment to the answer by theredled that you "add new content regularly and loading that in embeded iframes is quicker than writing new html every time" I have to ask this: aren't you using a templating system in your website?

Keep in mind that making AJAX-loaded content and using fragment identifiers to display the right content is not done because the page creation is easier (it isn't) but because the user experience is faster and more responsive. See for example the website for the SoundJS library:

When you click the link to PreloadJS at the top you go to:

The content is reloaded, the address bar changes, but the page is actually not reloaded. (You can see that it is properly crawlable because it shows in the results if you google for ReloadJS.)

Community
  • 1
  • 1
rsp
  • 107,747
  • 29
  • 201
  • 177
  • We used to be, however we decided that rather than linking to our templates formatting for every peice of content, binding content to the template would be faster for us, as we do add content frequently – Code Bundle Oct 30 '12 at 12:37
  • I'll vote this up, as this is a good responce, however I want to set this up so that people who have bookmarked www.website.com/about/ get redirected to the main page and about content loaded in it. Is that possible with these methods? – Code Bundle Oct 30 '12 at 12:38
  • @CodeBundle for working with fragment identifiers (# hash parts) and redirects see this question: http://stackoverflow.com/questions/2286402/url-fragment-and-302-redirects – rsp Oct 30 '12 at 12:40
  • 2
    I would second @rsp's point: this is not the right way to do it. If editing HTML is a pain, install Joomla or some other CMS. Just don't fill your page with iframes so you can edit it easily. It's like printing a letter's contents on a blank page (carefully aligned) and inserting it into an envelope with your letterhead printed on, so the content shows through the little window. – Phil H Oct 30 '12 at 12:45
  • @PhilH Nice analogy :) but we don't have the facility to use external tools in this situation. – Code Bundle Oct 30 '12 at 12:52
  • I've accepted this as for most people It would be right, I'm gonna bodge something together for my situation, seems like bodging is all that happens on my site :D – Code Bundle Oct 30 '12 at 12:58
1

Pass content by a user session ?

However, it's a quite dirty case, maybe you already know that :)

theredled
  • 998
  • 9
  • 20
  • Dont really understand your responce, and yes I know what I'm trying to do is a bodge for a bad way of writing a website, but it's functional as we add new content regularly and loading that in embeded iframes is quicker than writing new html every time. – Code Bundle Oct 30 '12 at 12:31