View Full Version : setting parameters in head for a repeated script in body
Hi guys,
I hope I was clear enough in the title :)
I have this script repeated many times thorughout a page and it makes things a bit of a bum if I want to change a specific bit.
So I am looking for a way to set a script at the top of the page so that when I put a trigger in this link, it (the script at the top), controls the changeables ie _blank, toolbar width height resizeable and scrollbars
<a class="bookmarklink" href="../folder/subfolder/index.htm" onFocus="if(this.blur)this.blur()" target="_blank" onclick="window.open('../folder/subfolder/index.htm','_blank','toolbar=yes,width=650,height=450,resizable=no,scrollbars=no'); return false">name of premises</a>
Is there a way to do it. I have searched but didnt see anything. Indeed if there is a way to set it in an external .js, that would be even better.
Thanks
cheesebagpipe
05-01-2003, 01:36 AM
You can make your functions as generic as necessary, by simply removing as many of their specific parameters as necessary, and then passing them into it via the call, either literally, or by referencing a variable. Just substitute a generic window opening function for your hardcoded one:
var pWin = null;
function winOpen(url, name, features) {
pWin = open(url, name, features);
if (pWin && !pWin.closed) pWin.focus();
}
<a class="bookmarklink" href="../folder/subfolder/index.htm" onFocus="if(this.blur)this.blur()" target="_blank" onclick="winOpen('../folder/subfolder/index. htm','_blank','toolbar=yes,width=650,height=450,re
sizable=no,scrollbars=no'); return false">name of premises</a>
If you want to simplify further, put various combinations of features in an object, and reference that:
var chrome = new Object();
chrome['bookmarklink'] = 'toolbar=yes,width=650,height=450,re
sizable=no,scrollbars=no';
chrome['tooltip'] = 'toolbar=no,width=250,height=150';
<a class="tooltip" href="../folder/subfolder/index.htm" onFocus="if(this.blur)this.blur()" target="_blank" onclick="winOpen('../folder/subfolder/index. htm','_blank',chrome['bookmarklink']); return false">something</a>
Thank you Cheesebagpipe.
Is it as simple then as plonking this in my head tags:
var chrome = new Object();
chrome['bookmarklink'] = 'toolbar=yes,width=650,height=450,re
sizable=no,scrollbars=no';
chrome['tooltip'] = 'toolbar=no,width=250,height=150';
And then this is the body of the page?
<a class="tooltip" href="../folder/subfolder/index.htm" onFocus="if(this.blur)this.blur()" target="_blank" onclick="winOpen('../folder/subfolder/index. htm','_blank',chrome['bookmarklink']); return false">something</a>
cheesebagpipe
05-01-2003, 02:35 AM
Even simpler:
In your base (e.g., 'JS_core.js') JavaScript file:
----------------------------------------------------------
var chrome = new Object();
chrome['bookmarklink'] = 'toolbar......etc.
var pWin = null;
function winOpen(url, name, features) {
pWin = open(url, name, features);
......etc.
----------------------------------------------------------
In every page that needs it (in header):
<script type="text/javascript" language="javascript" src="JS_core.js"></script>
Thanks Cheesebagpipe, I'll try that.
:thumbsup:
I've tried but not yet succeeded :(
In your base (e.g., 'JS_core.js') JavaScript file:
----------------------------------------------------------
var chrome = new Object();
chrome['bookmarklink'] = 'toolbar......etc.
var pWin = null;
function winOpen(url, name, features) {
pWin = open(url, name, features);
......etc.
----------------------------------------------------------
FYI, (you may realise this already),
bookmarklink is the name of the class for .css file
I can see where to put the toolbats width etc but where you show (url, name, features) do I have to name each hyperlink and what features should I put in?
soory if that makes me sound a fikko :(
OK this is what I have done: -
In the head of my doc:
<script type="text/javascript" language="javascript" src="name of jsfile.js"></script>
In the .js file (C+P'd).
var chrome = new Object();
chrome['bookmarklink'] = 'toolbar=yes,width=650,height=450,re
sizable=no,scrollbars=no';
chrome['tooltip'] = 'toolbar=no,width=250,height=150';
//-->
This is whats in the body of my page.
<a class="bookmarklink" href="folder_location" onFocus="if(this.blur)this.blur()" target="_blank" onclick="winOpen('folder_location','_blank',chrome['bookmarklink']); return false">something</a>
It isn't working. It just opens the new window as if I have excercised no controls on it.
cheesebagpipe
05-02-2003, 05:46 AM
[jsfile.js] :
<!--
var pWin = null;
function winOpen(url, name, type) {
pWin = open(url, name, type);
if (pWin && !pWin.closed) pWin.focus();
}
var wintype = new Object();
wintype['bookmarklink'] = 'toolbar,width=650,height=450,left='+(screen.availWidth-650)/2+',top='+(screen.availHeight-450)/2;
wintype['tooltip'] = 'toolbar=no,width=250,height=150,left='+(screen.availWidth-250)/2+',top='+(screen.availHeight-150)/2;
//-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" />
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript" src="jsfile.js"></script>
</head>
<body>
<a class="bookmarklink" href="folder_location" onFocus="if(this.blur)this.blur()" target="_blank" onclick="winOpen(this.href,'bookmarklink',wintype['bookmarklink']);
return false">something</a><br /><br />
<a class="tooltip" href="tooltip1" onFocus="if(this.blur)this.blur()" target="_blank" onclick="winOpen(this.href,'tooltip',wintype['tooltip']);
return false">anything</a>
</body>
</html>
Thanks Cheesepbagpipe ut guess what.
I've copied and pasted and stilll can't get it to work:(
Doh!! It would help if I used the correct root for the .js file.
So just for the record, it was my mistake and not cheesebagpipes. :)
Now can nayone tell me how to add to the script to control the positioning of the new window. I want it 0px from the top left on both the x and y axes.
many thanks
bazz
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.