PDA

View Full Version : Javascript Redirection


Gav_Roberts2k2
01-23-2003, 04:28 PM
Well i have posted a thread here before and you helped me, so maybes you can help me again.

I have created a script that the browser will refer to when a link is pressed. I created a graphical menu for my site, and The link changes depending on the page due to the location of the page.

Like all my pictures; I have to add or take away the ../ from the links depending on the depth of the page.

Anyway onto the script. This is the script I created.

<Script language="javascript">

function nav(n) {

if (n == home)
{ window.open('index.shtml'); }
else if (n == design)
{ window.open('design/index.shtml'); }
}

</script>

That is only half of the script.

What I wanted it to do is when I assign javascript:nav(home); to a link it will refer to the script and execute the url in the browser.

The only problem is that it opens a new window. What I am looking for it to do is load the content into the default window.
i.e. _self

I have tried adding
{ window.open('index.shtml','_self'); }
and
{ window.location.href="/index.shtml" }

Infact I have tried everything I know. :(:confused:

So if anyone out there knows how to do this, PLEASE email me or reply....

I will add the thank you notes to the script and the page if you can help.

Thanks

arnyinc
01-23-2003, 04:43 PM
window.open(link, target) should work.
More specifically, window.open('index.shtml','_self'); should work.

When you call nav(home), you are calling it with a variable. Is that variable set equal to anything? I think you need to change your function calls and if-statements to static values.

i.e. nav('home')

i.e. if (n == 'home')

Danne
01-23-2003, 04:45 PM
Try this:



function nav(n)
{
if (n == "home")
window.location="index.shtml";
else{
window.location=n+"/index.shtml";
}




...n being a string...:rolleyes: