View Full Version : open.window
charter
12-12-2002, 07:28 PM
Can any of you gurus please help?
I have a script on a webpage to open an new window of a certain size.
If I want all the pages of the website to open the same size do I have to put the script on every page?
I want the pages to open in this same window.
All Help much appreciated
ACJavascript
12-13-2002, 12:14 AM
I would create a function to handle all the windows on that page like this.
_________________
<script langauge="javascript">
function open(url){
window.open(url,"WindowName","height=300,width=400")
}
</script>
______________________
You then call it in the link or button..
<a href="javascript:open('http://www.yoursite.com');">Click here for your site</a>
Hope that helps.. :thumbsup:
cheesebagpipe
12-13-2002, 12:20 AM
Might want to rethink that. open() isn't the best name for a top-level function to open a browser window by calling, erm, window.open(). Other names available.
charter: when you've got the function you want, you can put it in a separate .js file written into every page:
<script type="text/javascript" src="script.js"></script>
If it's just the one function, however, this might be overkill.
ACJavascript
12-13-2002, 01:02 AM
Your right cheese,,
<script langauge="javascript">
function go(url){
window.open(url,"WindowName","height=300,width=400")
}
</script>
______________________
You then call it in the link or button..
<a href="javascript:go('http://www.yoursite.com');">Click here for your site</a>
cheesebagpipe
12-13-2002, 01:29 AM
<a href="javascript:void go('http://www.yoursite.com');">Click here for your site</a>
Keeps your main page.
glenngv
12-13-2002, 01:51 AM
...or better, like this so that it will degrade well for javascript disabled browsers.
<script langauge="javascript">
function go(url,target){
window.open(url,target,"height=300,width=400")
return false;//cancels href if called on <a> tag
}
</script>
You then call it in a link:
<a href="http://www.yoursite.com" target="WindowName" onclick="return go(this.href,this.target)">Click here for your site</a>
or in a button:
<input type="button" value="Open" onclick="go('http://www.yoursite.com','WindowName')">
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.