New Windows using JavaScript
JavaScript is extremely useful, it is almost a complete programming language. the only problem you might face is when somebody using a very old browser accesses…
JavaScript is extremely useful, it is almost a complete programming language. the only problem you might face is when somebody using a very old browser accesses your site. These scripts just stop working.
Opening links in new windows
To open a link in a new window we will use a simple javascript function. the function will be placed between <script> </script> tags in the <head> part of your document (it will come just below your <title> </title> tags) This is how it works. the function is as follows
function openLink( url ) {
var msg = window.open(url,
"displayWindow", "HEIGHT=640, WIDTH=400, status=no, toolbar=no,
scrollbars=yes, directories=no, menubar=no, location=no");
if(navigator.appName == "Netscape")
msg.creator = self;
}
change the values from no to yes to activate any of the above.
change the values of height and width to change the size of
the window.
using the function
whenever you have to link to a page which you want to open in a new window, use the following piece of code,
<a href="javascript:openLink('somename.html');">click here</a>
replace the somename.html with the name of the file you want to link to.
and in completion…
I have used the <!– at the beginning of the script tag
and the // –> to hide this from older browsers which do
not recognise javascript (that would mean really really old
versions of netscape and old versions of IE)
oh yes if you don’t like the function name change it, but
i would appreciate it if you could put in a line of code giving
me credit
<!– javascript help - narendra nag .. naren.8m.com –>
or something along those lines
here’s an example cut and paste this code into a blank document, save it as test.htm and open it in your favourite web browser…see what happens.
Originally published on naren.8m.com, my first website, in 1999; recovered from the Wayback Machine.