PDA

View Full Version : Opening a new window based on a cookie


habib
09-20-2002, 05:11 PM
Hi,

I am stumped with this problem I'm having. I am trying to open a new window and load a htm page in the window based on the result of a cookie. If the cookie value is SA, then I want to open sahome.htm in a new window for the user. When I preview the page I dont get any errors but when I click on 'Click here' a new window loads but sahome or ukhome dont load up.

Help!

function select_country () {
if (getCookie('home_location') == 'SA' ) {
window.open('sahome.htm') }
else {
if (getCookie('home_location') == 'UK' ) {
window.open('ukhome.htm') }
}
}

<a href = onClick="select_country();">Click here!</a>

Thanks in advance for your help
HR

Mr J
09-20-2002, 07:06 PM
Not too sure about this but try the following.
This assigns the cookie value to a variable first


function select_country () {
var where=getCookie('home_location')
if (where == 'SA' ) {
window.open('sahome.htm') }
else {
if (where == 'UK' ) {
window.open('ukhome.htm') }
}
}

<a href = onClick="select_country();">Click here!</a>

Mr J
09-20-2002, 07:46 PM
I thought I'd try your function out and found that it seem alright and worked.

It loaded the correct page for the right value.

Could it be that the file paths are incorrect.

Do you get:

The page cannot be displayed

message?

:confused:

boywonder
09-20-2002, 09:32 PM
You might wanna fix this: (unless it's just a typo in the post)

<a href = onClick="select_country();">Click here!</a>

<a href="#" onClick="select_country(); return false;">Click here!</a>

habib
09-23-2002, 10:06 AM
Dear Mr J,

When I click on the link it doesn't load the new page, I get the page cannot be displayed message, and in the url bar I get the previous file address.

For example if I put the function in test.htm and then preview the page, when I click on the link I get:

Page cannot be displayed error and in the url bar I get:

W:\public_html\test.htm#

The file that contains the function and the file that I am linking to are both in the same directory (public_html), all my htm files are stored in the same directory. If my function worked when you tried it suggests to me that it could be incorrect file paths but I'm not sure why it could incorrect.

I also tried having the file paths as:

function select_country () {
var where=getCookie('home_location')
if (where == 'SA' ) {
window.open('W:/public_html/sahome.htm') }
else {
if (where == 'UK' ) {
window.open('W:/public_html/ukhome.htm) }
}
}

<a href ="#" onClick="select_country();">Click here!</a>

it works like a dream. I just cannot figure it out!

:confused: