Need javascript help
March 13, 2005 6:18 PM
Subscribe
I'm having a problem with some javascript, and comp.lang.javascript has not been much help. Any mefites care to try their hand?
I normally work on the middle tier objects, but have been tasked with working on some front end stuff. Unfortunately, my javascript skills are not up to stuff. Anyways:
I have a javascript file called 'PMP.WEBSITE/Scripts/Popups.js' (PMP.WEBSITE is the root of the website). In that file is the following function:
function OpenTutorial(sTutID)
{
var sURL = '../support/tutorials.aspx?tutid=' = sTutID;
var sProperties = 'center:yes;etc..';
window.showModalDialog(sURL, self, sProperties);
}
where ../support is actually PMP.WEBSITE/support.
Most of the website pages are located in sub folders from the root of the website. When editing is to be done on a record, a popup window is called from the main page. The popup pages are in another sub folder (i.e. pmp/review would be where review.aspx resides and the edit page would be located at pmp/review/popups). We give the user a tutorial icon to click on which calls the OpenTutorial function on a button click event.
Each page that calls the popup function has the following reference to .js file:
[script language="javascript" src="../scripts/popups.js" type="text/javascript"][/script] with the src attribute changing as required based on the page's location in the site
The problem is the tutorial popup page won't load properly when called from another popup page. I've tried variations of location.href, location.pathname, location.hostname etc.. but can't seem to get the pages to open correctly. The most common error i get is that the url is not correct. here is a sample of the urls being called by the function:
pmp/review/support/tutorials.aspx
pmp/feedback/support/tutorials.aspx
pmp/thirdparty/support/tutorials.aspx.
Any suggestions on how i can get the function to point to pmp/support/tutorials.aspx regardless of where the function is being called from? One reply from newsgroups said '/pmp.website/support/tutorials.aspx' but that didn't work.
posted by smcniven to computers & internet (10 comments total)
However, your tutorial.aspx pages apparently expect a tutid parameter. Is it possible that different tutorials expect different parameters, and return an empty page or error page id the expected parameter is not given?
The OpenTutorial function implies that its sTutID parameter includes a closing but not an opening single quotation mark. (This is sloppy.) When you are attempting to invoke other tutorial pages, are you "correctly" including the closing but not the opening single quotation mark?
A slightly more robust solution would be to replace your OpenTutorial function with this one (note that the replacement starts with a lower-case letter to adhere more closely to accepted Javascript style):
function openTutorial( sTutID, path ) // use default path unless other path is given
{
path = ( path ? path : "../support/tutorials.aspx" ) + "?tutid='" + sTutID;
var sProperties = 'center:yes;etc..';
window.showModalDialog(path, self, sProperties);
}
Some other notes:
The line:
var sURL = '../support/tutorials.aspx?tutid=' = sTutID;
is very suspicious, although probably legal. Is the second assignment operator really meant to be the catenation ("+") operator?
posted by orthogonality at 6:35 PM on March 13, 2005