473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Var find/var repl/var page/.../document.body.innerHTML = page;

No idea what I'm doing or why it isn't working. Clearly not using the right method and probably won't use the right language to explain the problem..

Photogallery.. Trying to have a single html page.. it has links to images.. buttons on the page 'aim to' modify the path to the images by finding the name currently in the path and replacing it with the name of the gallery corresponding to the button the user clicked on..

example:

Expand|Select|Wrap|Line Numbers
  1.     GALLERY2go : function(e) {
  2.         if(GalleryID!="landscapes")
  3.         {
  4.         var find = ''+ findGalleryID()+'';
  5.         var repl = "landscapes";
  6.         var page = document.body.innerHTML;
  7.         while (page.indexOf(find) >= 0) {
  8.         var i = page.indexOf(find);
  9.         var j = find.length;
  10.         page = page.substr(0,i) + repl + page.substr(i+j);
  11.         document.body.innerHTML = page;
  12.         var GalleryID = "landscapes";
  13.         }
  14.         }
  15.     },
There's a function higher up the page to get var find to take the value of var GalleryID

Expand|Select|Wrap|Line Numbers
  1. var GalleryID = "portfolio";
  2.  
  3. function findGalleryID() {        
  4.     return GalleryID
  5. }
Clearly the first varGalleryID is global and the one inside the function is clearer at the end of the function (I've read that much). But I don't know what any of this means.

The code, given its frailties or otherwise ridiculousness, actually does change all of the image links (and absolutely everything else called "portfolio") in the html page - hence "portfolio" becomes "landscapes".. the path to the images changes and they all update.. As a JavaScript beginner I was pretty chuffed to see it worked. But you can't click on another gallery button because it's stuck in a loop of some sort. In fact, after you click the button you can't click on anything else and all of the rest of the JavaScript functionality is buggered. Perhaps I've introduced some kind of loop it never exits. If you click on portfolio when you're in portfolio you crash the browser! Anyway I'm well aware that 'my cobbled together solution' is not how it would be done by someone with any experience in writing code. They'd probably use something else with a different name that takes another lifetime to learn. I don't think I can use getElement by and refer to the class/id name and parse the filename [using lots of words I don't at all understand] because of the implications on the other parts of the script. I've tried using a div wrapper and code to launch a child html doc and that come in without disposing of the existing content or talking to the stylesheet. I'm bloody lost and don't even know where to start looking next.
Mar 15 '12 #1
1 2049
Dormilich
8,658 Expert Mod 8TB
the main problem I see is that you try to replace the GalleryID string in the complete HTML code. that is bound to have some side effects somewhere.

Expand|Select|Wrap|Line Numbers
  1. var GalleryID = "portfolio";
  2.  
  3. function findGalleryID() {        
  4.     return GalleryID
  5. }
Clearly the first varGalleryID is global and the one inside the function is clearer at the end of the function (I've read that much). But I don't know what any of this means.
that structure is called a Closure. but in this case it's absolutely pointless since it only returns the unmodified, untreated variable it closures.

buttons on the page 'aim to' modify the path to the images by finding the name currently in the path and replacing it with the name of the gallery corresponding to the button the user clicked on..
the question is, where are those paths? there is certainly a way to get them without interferring elsewhere. (but that would require the knowledge of where to find them).

and getting the name (or whatever data) of the button you clicked on is not that complicated either (in a triggered event this refers to the element in process)
Mar 16 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Reed | last post by:
I'm having a problem with apostrophes & quotes when using body.innerHTML. With the statement: bodyText = document.body.innerHTML If there was a Form object on my page such as: <input...
14
by: christopher.secord | last post by:
Can someone please tell me why this works: document.body.innerHTML = "<table><tr><th>one</th></tr><tr><td>two</td></tr></table>"; But this does not work: document.body.innerHTML =...
2
by: robert.waters | last post by:
Hello, I am dynamically editing the contents of a page and using document.write() to reload the new, edited content. However, on the new page, any calls to functions located in external .js...
1
by: Mike John | last post by:
how can i include the current page in the body of the email. I was only to put text. Syntax: <html> <body> <input type ="Button" onclick= "eman()"> <SCRIPT LANGUAGE=JAVASCRIPT>
3
by: daveyand | last post by:
Hey Guys, Am stuck, i need to create an overlaying DIV to a webpage, but i want it to go over only the HTML content of the page. So if the page is only within the middle 500px of the screen i...
3
by: SJ | last post by:
Hi, So I am trying to save off my source HTML to an xml document in order to cache a large view within my ajax app. For those of you familiar with this, the innerHTML does not preserve the...
3
by: jnag | last post by:
I am trying to implement font changer, where I have links on the banner of the site and when the user clicks on the links, the font size of the page has to change. I tried...
4
by: kiransasi | last post by:
hi all, i m herewith struck with this problem.... check out the following code and lemme know the solution for this.... <html> <heAD> <TITLE>WAIT</TITLE>
1
by: jsuser | last post by:
This is to discuss pros and cons of each other.
1
by: Duke | last post by:
<html> <head> <script type="text/javascript"> function init(){ var html = document.open('Hello.html'); document.getElementById('hi").innerHTML = html; } </script> <body onload ="init();">...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.