Click to See Complete Forum and Search --> : redirection based on value of title--easy one


dotnetanimal
01-06-2003, 05:37 PM
Hi all. I have been looking and this and can't figure out where I am failing. Does anyone see a problem in logic? I want to pass the title value to a page and have it display a different page depending on the input.

function pageTitle()
{
if (pagetitle = "Reporting Home")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=reports.html"
}
if (pagetitle = "Bad Request")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Compare Group Editor")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Compare Group Editor Static")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Compare Group Manager")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Export Page")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Access Denied")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Blah")
{
window.location.href="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Blah")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
if (pagetitle = "Blah")
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=administration7.html"
}
else
window.open("Zephyr Reporting Home", target="_self")
}

swon
01-06-2003, 05:47 PM
hi, do you want a new location or a new window?
The reason I'm asking is you have on a few lines window.open and another line a window.location.href.

dotnetanimal
01-06-2003, 05:49 PM
New window redirecting the user to the new page. I am actually passing this from a help link on the main page but need to grab the title too. Passing to another page on the site

Zach Elfers
01-06-2003, 05:53 PM
Use location.href instead of window.open and use window.title instead of pagetitle. Then it might work.

Charles
01-06-2003, 06:01 PM
1 - "=" is the Simple Assignment operator and it returns the value on the right hand side. Thus if (pagetitle = "Reporting Home") always evaluates as true. "==" is the Equals operator.

2 - You want to use the switch statement. See http://developer.netscape.com/docs/manuals/js/client/jsref/stmt.htm#1018610.

3 - You need to see http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm#1202731.

dotnetanimal
01-06-2003, 06:08 PM
I looked at the links and this is what I come up with on this one. I think I am still passing variables in wrong though. I want to pass in the page title and based on the string value that is returned like "Zephyr Reporting Home" open a different link on the site.

I am interested in doing this correctly and learnining why what I am doing is wrong. Thanks for the links I have bookmarked them as a resource--after reading them.


Ok so something like this then?

Looks like a better way to do it.

var pagetitle = document.title;
//document.write(pagetitle);


function pageTitle()
{
switch (pagetitile)
{
case "Zephyr Reporting Home" :
{
window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=reports.html"
}

Charles
01-07-2003, 05:56 AM
Your line window.open="/reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=reports.html" means assign the string literal /reports/help/wwhelp/wwhimpl/js/html/wwhelp.htm?href=reports.html to the open property of the window object. Most likely this is not what you want. JavaScript is a very complicated, object oriented language that doesn't work the way the untrained mind does. You cannot learn it with tutorials or by playing around with it. You must make a thorough and systematic study of it. Read several times, cover to cover the book JavaScript : The Definitive Guide by David Flanagan (http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=553C7VH1SX&isbn=0596000480&itm=1)