Forum Moderators: open

Message Too Old, No Replies

location.hash

         

webaster

2:48 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



is it possible to do this:

<a href="page.html#1"></a>
<a href="page.html#2"></a>
<a href="page.html#3"></a>

Can you use the replace method with extracting the hrefs?

By means of iteration?

webaster

3:08 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



function replacer(Url){
var isIe = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (/opera/i.test(navigator.userAgent));
if(isOpera ¦¦ isIe) {

//Is this correct?

window.location.replace( 'page.html'+document.location= .hash ) ;


}

}}

function Iterator()
{
var galleryLinks; // use local var
if(document.getElementById) // thus getElementsByTagName support assumed
galleryLinks = document.getElementById('gallery').getElementsByTagName('a');
else if(document.all)
galleryLinks = document.all.gallery.all.tags('a');
else return // reject NS4 etc
for (var i=0;i<galleryLinks.length;i++)
galleryLinks[i].onclick = replacer;

}

Is it possible to extract the href and then use location.replace

The Code

<ul id="gallery">
<li><a href="page.html#1"></a><li>
<li><a href="page.html#2"></a><li>
<li><a href="page.html#3"></a><li>
</ul>

Rambo Tribble

3:21 pm on Mar 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think, perhaps, you're crossing up location.replace() with String.replace(). location.replace() affects the window's history object by not entering the URL of the page calling the method, but replacing it in the history list with the target URL that is the parameter of the method.

String.replace(), which is method of the String object, allows the use of a regular expression to find and replace character patterns in a string. Since the href value is a string, you could use String.replace() to alter it, then assign the location's href, either directly or through the location.replace() method, the new value.

webaster

3:34 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



illustrate with the given example please -

webaster

3:42 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



actually my problem is to solve the easiest way is that when I click on a link to the problematic displaying page that this page gets refreshed once automatically after all other scripts are executed - is this cross-browser IE, mozilla, Safari,netscape possible

function replacer(){
var isIe = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (/opera/i.test(navigator.userAgent));
if(isOpera ¦¦ isIe) {

window.location.reload( 'samepage.html' ) ;
}}

Rambo Tribble

4:52 pm on Mar 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The location.reload(); method takes no arguments and does a hard reload on the current page. The problem is, if you call it with an onload event, you've got an endless loop.

webaster

4:57 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



and how can you fix the looping - fully aware of the looping - when using location.replace reffering to the same url onload can circumvent this issue - have a working example

that is all I need just once after all the previous javascript code blocks are executed - you are the experts

Rambo Tribble

10:04 pm on Mar 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Clearly, you will have to employ some form of persistence to prevent the endless loop. You can use cookies, passed parameters in the URL, modifications to window.name; pick your poison and code accordingly, reloading or assigning the href conditionally.

Oh, and there might be some confusion; I think we may all be exspurts here, defined thusly: an ex is a has-been and a spurt is a drip under pressure.

webaster

11:01 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



no example or Url

Rambo Tribble

11:13 pm on Mar 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps you have mistaken me for your research assistant.

Bernard Marx

11:28 pm on Mar 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



:>

webaster

11:34 pm on Mar 13, 2005 (gmt 0)

10+ Year Member



function replacer(){
var isIe = (navigator.appName == "Microsoft Internet Explorer");
var isOpera = (/opera/i.test(navigator.userAgent));
var clickedLink = document.getElementById('gallery').getElementsByTagName('a').href;
if(isOpera ¦¦ isIe) {

window.location.replace('clickedLink');
alert("function works");

}

}

// going back and forth from thumbs to Opera and IE workaround

function iteratorLinks()
{
var galleryLinks; // use local var
if(document.getElementById) // thus getElementsByTagName support assumed
galleryLinks = document.getElementById('gallery').getElementsByTagName('a');
else if(document.all)
galleryLinks = document.all.gallery.all.tags('a');
else return // reject NS4 etc
for (var i=0;i<galleryLinks.length;i++) {
galleryLinks[i].onclick = replacer;

}
}
addEvent (window,'load',iteratorLinks)

all is correct?