Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maan, I think I understand now what you want to do. You want to be able to reset the src of the image on all your numbered pages without having to change it manually. This is doable with Javascript, though I'm not sure it's strictly advisable, because it means the image will be wrong for browsers which don't have JS enabled. That's a very unusual case, but it might include Googlebot - so if it's important that the image is correct for SEO purposes you probably have no alternative but to change all your image filenames.</p> <p>For what it's worth, this JS should do what you want. </p> <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function () { var currentPage = window.location.href.split('/'); var currentNum = currentPage[3].split('.')[0]; $('img').attr('src', 'Images/' + currentNum + '.jpg'); $('#prev').click(function () { move(-1); }); $('#next').click(function () { move(1); }); function move(n) { window.location.href = Number(currentNum) + Number(n) + '.html'; } }); &lt;/script&gt; </code></pre> <p>This bit includes JQuery in your page</p> <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; </code></pre> <p>The bit inside <code>$(document).ready(function () { ... }</code> is run when the page is ready to display, usually before it's loaded.</p> <p><code>var currentPage = window.location.href.split('/');</code> gets the current URL of the page and splits it at each / character. This line produces an array which contains the parts of the URL. If your URL is <a href="http://jsut4fun.site40.net/5.html" rel="nofollow">http://jsut4fun.site40.net/5.html</a>, "5.html" will be the fourth part, which is located at index position [3] of the array.</p> <p><code>var currentNum = currentPage[3].split('.')[0];</code> grabs the fourth part of the URL and splits it at the '.' This gives us the page number.</p> <p><code>$('center img').attr('src', 'Images/' + currentNum + '.jpg');</code> resets the src attribute of your main image to the right URL for the page. 'center img' selects any image which is a child of a center element.</p> <p>You could keep your existing links and prevImage() and nextImage() functions to move between pages, but if you wanted to do this with JQuery as well you could do it with the bit that says</p> <pre><code>$('#prev').click(function () { move(-1); }); $('#next').click(function () { move(1); }); function move(n) { window.location.href = Number(currentNum) + Number(n) + '.htm'; } </code></pre> <p>This example assumes the links have the ids "prev" and "next". It should be easy enough to add ids to your current links on every page with a global search and replace.</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload