PDA

View Full Version : External JS file in Netscape 4


de-pad-dp
03-12-2003, 03:47 PM
Hi

Having a bit of a problem today. I have a external JS file that is used on every page of my site using the following code

<script language="JavaScript" src="code/global.js" type="text/javascript"></script>

Everything works fine until I want to use a function/ variable from this external JS file from a new window that has been opened via a script from the original window.

eg

window.open("newwin.htm","contact","width=500,height=450,left=0,top=0,menubar=no,scrollbars=yes,resizable=no,status=no,toolbar=no,locati on=no");

in this new window it is finding the js file as it isnt giving my page cannot be found. I have renamed the file and received page cannot be found to test the file is found.

The strange thing is that everything is fine if i reload the page in the new window. I have a browser detection in the JS file. When document in new window loads, if i do a test for netscape it will be false, when I reload the doc it will test true.

The events are as follows

1. On main Page all code is accessable from JS file
2. Open window from main page
3. do a test that should be true relying on JS file
4. test comes back false
5. reload doc, test comes back true

Hope this makes sense, any advice would be great

Dean

de-pad-dp
03-12-2003, 05:17 PM
Just a follow up to my initial post.

From the new window, the functions are being called but the variables are undefined until the page is reloaded.

eg

I call a function that is located in the JS file to open a page in the opener window. I have a variable that holds the base url


var servername = location.hostname
var baseloc = "http://" + servername + "/";


// function will goto a url in original window, must be passed a relative url as base will be added in the function

function dp_closeredirect(url) {

opener.location.href = baseloc + url

self.close()

return false;

}

With this if i pass function "contact/index.htm", the window closes and the opener goes to:

undefinedcontact/index.htm

so baseloc is undefined

if i refresh page before clicking link to call function it does what its supposed to:

http://www.myserver.com/contact/index.htm

IE is fine and dont have a problem

Thanks

Dean