Hi,
I am using some javascript to produce a new window for my
account info. It is designed to be opened looked at and then closed again.
But apparently the code is a bit old fashioned
(somebody made that remark but did not suggest how to
update it :( )
So this is my bit of code: - <script language="javascript" type="text/javascript">
-
<!--
-
var win=null;
-
function NewWindow(mypage,myname,w,h,scroll){
-
LeftPosition=300;
-
TopPosition=150;
-
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
-
win=window.open(mypage,myname,settings);
-
if(win.focus){win.focus();}}
-
-
function hidestatus(){
-
window.status=''
-
return true
-
}
-
-
if (document.layers)
-
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
-
document.onmouseover=hidestatus
-
document.onmouseout=hidestatus
-
-
// -->
-
</script>
And the HTML that calls it: -
<!-- // SF-Code Affiliate Marketing ##ak18d54kt** // -->
-
<a href="http://www.support-focus.com/check.php?key=SFM64912"
-
onclick="NewWindow(this.href,'','860','700','yes','default');
-
return false" onfocus="this.blur()" >
-
<img src="http://www.support-focus.com/image_load.php?id=SFM64912"
-
alt="Support-Focus Membership Click to Verify - Before you Buy" border="0" ></a>
Apparently,
<script language="javas cript" type="text/javascript">
and
document.layers
and
<!-- // comment // -->
are all long deprecated and obsolete.
It was also suggested that I place semi colns at the end of lines and
use more { and }
BuT I am not sure where to use them.
Any suggestions and help much appreciated.
Thanks
9 1781 Dormilich 8,658
Recognized Expert Moderator Expert
Apparently,
<script language="javas cript" type="text/javascript">
and
document.layers
and
<!-- // comment // -->
are all long deprecated and obsolete.
more or less.
the correct script tag is now: <script type="text/javascript"> document.layers is only supported by Netscape 4 (which I doubt someone still uses)
javascript need not be wrapped in comment tags any more (except for XHTML, where you require CDATA tags)
the standard way of using events is via Element.addEven tListener() (not supported by IE, but there are lots of cross-browser solutions available)
Thanks for that.
So the comment tags the guy was talking about is just the ones in my javascript, not the ones in the HTML ?
As I already have the function,
function hidestatus() does that mean that I may as well
simply delete the if (document.layer s) block ?
So my code becomes: -
<script type="text/javascript">
-
var win=null;
-
function NewWindow(mypage,myname,w,h,scroll){
-
LeftPosition=300;
-
TopPosition=150;
-
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
-
win=window.open(mypage,myname,settings);
-
-
if(win.focus){
-
win.focus();
-
}
-
}
-
function hidestatus(){
-
window.status=''
-
return true
-
}
-
</script>
-
Anything else I need to do ?
One more question.
If I want to put the code on my server and just include the
js file with this: - <script type="text/javascript" src="http://www.example.com/code.js">
-
</script>
Does the code.js file also need to have the
script tags ( which would double them up ) or
shoul the file just contain the code without the
surrounding script tags ?
Dormilich 8,658
Recognized Expert Moderator Expert
does that mean that I may as well simply delete the if (document.layer s) block ?
yepp.
So the comment tags the guy was talking about is just the ones in my javascript, not the ones in the HTML ?
yes, although you should use comments, to document your code (be it HTML, JavaScript, CSS or anything else)
Anything else I need to do ?
move the events to the JavaScript.
ex. - // instead of
-
<a href="…" onclick="NewWindow(this.href,'','860','700','yes','default'); return false" onfocus="this.blur()" >
-
-
// you can do
-
<a id="test" href="…">
-
-
// addEvent() is one of the mentioned cross-browser solutions
-
// note that newWindow requires some rewriting
-
document.getElementById("test").addEvent("click", function() { newWindow(…)}, false);
-
// another note: the object oriented approach may come in handy here
what object oriented may look like: - function NewWindow(name, w, h, elem)
-
{
-
// some tests to prevent invalid values …
-
// width of new window
-
this.width = w;
-
// height of new window
-
this.height = h;
-
// name of new window
-
this.name = name;
-
// some window properties always delivered
-
this.defaultProps = "…";
-
this.prepareFor(elem);
-
}
-
-
// copy the object instance to the element, otherwise you’re out of scope later
-
NewWindow.prototype.prepareFor = function(elem)
-
{
-
// test if elem is really an html element …
-
elem.newWindow = this;
-
}
-
-
// method to make a new window
-
NewWindow.prototype.open = function()
-
{
-
var href = this.href;
-
// prevent normal href execution
-
this.href = "";
-
// open new window
-
window.open(href, this.newWindow.name, this.newWindow.properties());
-
}
-
-
// some more methods …
-
-
// how to use:
-
-
// create object
-
var link = document.getElementById("test");
-
var win = new NewWindow("boogle", 800, 600, link);
-
// add some properties …
-
-
// attach event
-
link.addEvent("click", win.open, false);
Thanks for spending the time to
write that oop but for this little bit of
code it seems a bit ott.
Your idea to move code out of the HTML and into the js
code is great. That is what I want to do but I did not follow what you
wrote :(
Does this bit of code go in the top (js portion)
or is it meant to stay in the HTML ? -
document.getElementById("test").addEvent("click", function() { newWindow(…)}, false);
You said I need to rewrite the newWindow ???
Dormilich 8,658
Recognized Expert Moderator Expert
but for this little bit of code it seems a bit odd.
that’s the only way, if you don’t want to use anonymous functions. besides, JavaScript is all about objects. objects are way more flexible than a simple function call, in the end, you don’t have that much more code.
Does this bit of code go in the top (js portion) or is it meant to stay in the HTML ?
despite the HTML code it is meant to stay in the JavaScript (resp. it is meant to stay out of the HTML)
You said I need to rewrite the newWindow ???
if you use elem.addEventLi stener("event", fn_callback, capture) then the event handler functions change the scope of the function fn_callback() (the meaning of " this" changes), which I use in the OOP approach.
you could even do something like - document.getElementById("test").setupWindow({name: "boogle", width: 800, height: 600, scrollbars: "yes" });
Dormilich 8,658
Recognized Expert Moderator Expert
I ended up with an implementation of Element.setupWi ndow() that barely takes up 40 lines…
acoder 16,027
Recognized Expert Moderator MVP
One more question.
If I want to put the code on my server and just include the
js file with this: - <script type="text/javascript" src="http://www.example.com/code.js">
-
</script>
Does the code.js file also need to have the
script tags ( which would double them up ) or
shoul the file just contain the code without the
surrounding script tags ?
Just the code without the tags because it's a JavaScript file and doesn't need HTML script tags.
Two quick points:
1. If you're going to delete the "document.layer s block", note that that meant just the one (or two lines) because the if statement only applied to the line below it. So, you would keep the following two lines: - document.onmouseover=hidestatus;
-
document.onmouseout=hidestatus;
However, if you're replacing this with the advanced event registration (addEventListen er or equivalent), then that's not a problem.
2. You should also look at your indenting. If you indent properly, it makes the code a lot easier to follow.
Thanks for your input.
I have ended up with 5 lines of code in my script
and I have stripped down my HTML as well. - var win=null;
-
function NewWindow(mypage,myname){
-
settings='width=850,height=500,top=200,left=50,scrollbars=yes,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
-
win=window.open(mypage,myname,settings);
-
if(win.focus){win.focus();}}
HTML: - <a href=\"http://www.example.com/index.php?key=$sup_cd2\"
-
onclick=\"NewWindow(this.href,''); return false\" onfocus=\"this.blur()\" >
-
<img src=\"http://www.example.com/image_load.php?id=$sup_cd2\"
-
alt=\"Click to Verify - Before you Buy\" border=\"0\" ></a>
This appears to be working fine..
Unless you see a problem with it, I think I'll use this as my default code but
if some clients want to be able to change the window position and size then I could supply a second version that allows the passing of those parameters.
It has been a useful excercise - I know a bit more now :)
Thanks for the OOP example, I am using some OOP in my php scripts, but in this case it just seems a bit unnecessary to create those objects and call them etc etc. when I can do what I need in 5 lines. But - thanks because working through it helped me a bit more with OOP.
If I have made a mistake with the code please let me know. thanks :)
acoder 16,027
Recognized Expert Moderator MVP
One other suggestion: you can avoid opening new windows by using DHTML (a window-like container within the page).
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Brandon J. Van Every |
last post by:
I'm realizing I didn't frame my question well.
What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump
up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN'
COOL!!! ***MAN*** that would save me a buttload of work and make my life
sooooo much easier!"
As opposed to minor differences of this feature here, that feature there.
Variations on style are of no interest to me. I'm coming at this from a...
|
by: Roy Yao |
last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ?
According to my analysis, operator sizeof, (type) and * have the same
precedence, and they combine from right to left. Then this expression should
equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why?
Can anyone help me? Thanks.
Best regards.
Roy
|
by: aling |
last post by:
What are top-down and bottom-up approach in C++ design? How do you
usually use them?
|
by: David A. Beck |
last post by:
When I do a debug.print("blabla") in VB (VS2005) it doesn't show up in the
output window, what gives?
|
by: sweetpotatop |
last post by:
Hello,
I wonder how I can open up a new browser from asp.net, I don't want a
pop up as users' machine might stop them from having pop. I use the
jscript window.ope, but that is a pop up. Can you please let me know
the alternative for having a new window up, but not pop-up please?
Thanks in advance.
Wanda
| |
by: Brian Henry |
last post by:
I posted a question about atlas twice now and it never showed up, did anyone
see it? i posted one last night and one today
|
by: efffemm |
last post by:
A few years ago, I heard of a program (maybe it is a plugin
for a well-know HTML editor) that cleans up the shit generated
when you save as html from Microsoft Word or PowerPoint, so that
it can be viewed in something other than IE6 ....
but I forgot what it was called.
Any ideas what it is?
|
by: Sin Jeong-hun |
last post by:
http://misako.co.kr/externaldata/Test.aspx
I've created a very simple user control which just has a label on it.
I followed the instruction but it doesn't show up. I don't know what's
wrong because there's no error message. It just showed an iframe-like
thing. Please let me know what went wrong. The user control itself can
be downloaded at
http://misako.co.kr/externaldata/Test.zip (I zipped it because
the .dll file cannot be...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - What books cover EcmaScript?
-----------------------------------------------------------------------
Most CLJ regulars believe the best book to be:
JavaScript: The Definitive Guide, 5th Edition By David Flanagan
ISBN:0-596-10199-6
The errata should be read along with the book.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |