Click to See Complete Forum and Search --> : Javascript
DanJericho
07-10-2001, 04:49 PM
I am working in a .js file, that I want to modify so that when I click on a link specified in the file, it will open in a new window. Currently, I've got it opening in the same window, but I want it in a new one. I know how to do it in HTML, but not sure about in javascript.
Thanks.
namgor
07-10-2001, 04:57 PM
I just wrote it for you, am i nice?
function OpenWindow3 (Turl) {
window.open(Turl,'c','toolbar=no,menubar=no,location=no,heig ht=300,width=250,resizeable=false'); }
uwcdc.com (http://www.uwcdc.com) or namgor.com (http://www.namgor.com)
DanJericho
07-11-2001, 12:56 PM
What is "Turl"?
BigTitan
07-11-2001, 01:30 PM
Originally posted by DanJericho:
What is "Turl"?
"Turl" is a variable that will contain the URL you want to open.
When you call the function (from, say, a input button), you would call the Javascript function passing in the URL as the only arguement.
reklis
07-11-2001, 03:05 PM
Originally posted by DanJericho:
What is "Turl"?
OpenWindow3("http://i.will.be.turl/");
------------------
Advocate of the Sharky (Ultra) High-Resolution Club [SHRC (http://www.sharkyforums.com/ubb/Forum17/HTML/005121.html)]
main(i){putchar(341513875>>(i-1)*5&31|!!(i<6)<<6)&&main(++i);}
DanJericho
07-11-2001, 04:48 PM
I'll put the code I have below. I'm trying to modify a js file that my boss gave me to work on. He wants some of the links off of a menu (which this is the code for) to open in a new window. I can't seem to find where it calls the new page. We use another js file to add the links to the menu.
Thanks.
*****
if (document.all) {n=0;ie=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;fShow="show"; fHide="hide";}
window.onerror=new Function("return true")
////////////////////////////////////////////////////////////////////////////
// Function Menu() //
////////////////////////////////////////////////////////////////////////////
rightX = 0;
function Menu()
{
this.bgColor = "#0073BD";
if (ie) this.menuFont = "bold xx-small Verdana";
if (n) this.menuFont = "bold x-small Verdana";
// this.fontColor = "white";
uwcdc.com (http://www.uwcdc.com) or namgor.com (http://www.namgor.com)
Grizzly
07-11-2001, 09:19 PM
That looks like a Folder Navigation Tree-style menu system. Pretty cool. But all that JS file does is generate links for the Nav Tree. That particular NavTree code doesn't support targeting new windows, but you can work around it if you want.
There are two seperate functions in there that generate links:
addSubItem(idParent, text, hint, location)
and
addItem(idItem, text, hint, location, altLocation)
Wherever you're calling those functions from, you need to change what is being passed as "location". (see 4th parameter in above functions)
Currently, I'm sure you have location being passed links like "main.html", or "pages/aboutus.html" or whatever...
Now...you can try two things:
1) Try changing the location you're passing from "main.html" to "JavaScript: window.open(\'main.html\',\'\',\'\')"
(Note: I escaped the single quotes in that sting, since I believe that's the only way it will parse through that function properly. Not sure, try it as I have it above, and if that doesn't work, than remove the escapes and see if that works.)
I really have no idea what that's supposed to look like in the end, but if you're looking for a good "Windows Explorer Style" NavTree, you can check out one I use pretty often here:
http://grizz.dhs.org/NavTree/
That one has "targeting" support for your Nav links, so you can easily target "_blank" with your links.
Good luck with it, I'll keep checking back here to see how you make out http://www.sharkyforums.com/ubb/biggrin.gif
Grizzly
07-11-2001, 09:50 PM
I ran some test to make sure if I gave you good advice or not, and you will indeed have to make a couple small edits to that .js file if you want this to work, with my
JavaScript: window.open(\'main.html\',\'\',\'\')"
...method above.
The changes you need to make are the following.
On line 84, make it say:
MENUitem += "href=\""+location+"\"' ";
On line 90, make it say:
MENUitem += "href=\""+altLocation+"\" ";
On line 146, make it say:
if (n) MENUitem = "<tr><td><a class=clsMenuItemNS title='"+hint+"' href=\""+location+"\"'>"+text+"</a><br></td></tr>\n";
On line 147, make it say:
if (ie) MENUitem = "<tr><td><a class=clsMenuItemIE title='"+hint+"' href=\""+location+"\">"+text+"</a><br></td></tr>\n";
Or...if you're don't feel like doing all that stuff above, I took the liberty of doing it for you. You can download the modified version of your JS file here:
http://grizz.dhs.org/edit.js
Note: This new JS file should be able to seamlessly replace the old one.
The only difference is it's now using double quotes with the href="" tag instead of single quotes. This will allow you to use the window.open function in the href="" tag.
Good luck buddy.
DanJericho
07-12-2001, 10:05 AM
Okay, I've got it opening in a new window now, which is great, but there's still a little problem.
After the new page is opened, the original page goes to a blank white page that says "[Object]" in the upper left and the title is " javascript: window.open('construction.htm',",") ". However, the address is still the origional page's address. If I hit refresh, that window goes to what the new one is, and if I hit Back, then I go back to to origional page.
Any ideas?
Thanks a lot for your help so far.
Grizzly
07-12-2001, 01:17 PM
Ahhh I see. Easy fix. I never knew this, but the open.window function, when used in the raw, returns an object. That's why you're seeing what you're seeing. I've always created my own pop-up functions to suit my needs, and here's one which should work for for you. You can toss this in the head of your document, OR, you can just paste it into your .js file (Remember to remove the <SCRIPT> tags if you place it in the .js file)
Use this funciton to open windows now:
<SCRIPT Language="JavaScript">
function openWindow(href){ window.open(href,'','') }
</SCRIPT>
So now, when you're passing "location" to your NavTree function, simply call it like this:
javascript: openWindow(\'construction.htm\')
[This message has been edited by Grizzly (edited July 12, 2001).]