473,657 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What are the up-to-date equivelents for this code?

290 Contributor
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:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. <!--
  3. var win=null;
  4. function NewWindow(mypage,myname,w,h,scroll){
  5. LeftPosition=300;
  6. TopPosition=150;
  7. settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
  8. win=window.open(mypage,myname,settings);
  9. if(win.focus){win.focus();}}
  10.  
  11. function hidestatus(){
  12. window.status=''
  13. return true
  14. }
  15.  
  16. if (document.layers)
  17. document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
  18. document.onmouseover=hidestatus
  19. document.onmouseout=hidestatus
  20.  
  21. // -->
  22. </script>
And the HTML that calls it:
Expand|Select|Wrap|Line Numbers
  1. <!-- // SF-Code Affiliate Marketing ##ak18d54kt** // --> 
  2. <a href="http://www.support-focus.com/check.php?key=SFM64912" 
  3. onclick="NewWindow(this.href,'','860','700','yes','default'); 
  4.  return false" onfocus="this.blur()" >  
  5.  <img src="http://www.support-focus.com/image_load.php?id=SFM64912" 
  6.  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
Jan 12 '10 #1
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)
Jan 12 '10 #2
jeddiki
290 Contributor
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:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var win=null;
  3. function NewWindow(mypage,myname,w,h,scroll){
  4.  LeftPosition=300;
  5.  TopPosition=150;
  6. settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
  7. win=window.open(mypage,myname,settings);
  8.  
  9.  if(win.focus){
  10.     win.focus();
  11.  }
  12.   function hidestatus(){
  13.     window.status=''
  14.     return true
  15.   }
  16.  </script>
  17.  

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:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://www.example.com/code.js">
  2. </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 ?
Jan 12 '10 #3
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.
Expand|Select|Wrap|Line Numbers
  1. // instead of 
  2. <a href="…"  onclick="NewWindow(this.href,'','860','700','yes','default');  return false" onfocus="this.blur()" > 
  3.  
  4. // you can do
  5. <a id="test" href="…">
  6.  
  7. // addEvent() is one of the mentioned cross-browser solutions
  8. // note that newWindow requires some rewriting
  9. document.getElementById("test").addEvent("click", function() { newWindow(…)}, false);
  10. // another note: the object oriented approach may come in handy here
what object oriented may look like:
Expand|Select|Wrap|Line Numbers
  1. function NewWindow(name, w, h, elem)
  2. {
  3.     // some tests to prevent invalid values …
  4.     // width of new window
  5.     this.width = w;
  6.     // height of new window
  7.     this.height = h;
  8.     // name of new window
  9.     this.name = name;
  10.     // some window properties always delivered
  11.     this.defaultProps = "…";
  12.     this.prepareFor(elem);
  13. }
  14.  
  15. // copy the object instance to the element, otherwise you’re out of scope later
  16. NewWindow.prototype.prepareFor = function(elem)
  17. {
  18.     // test if elem is really an html element …
  19.     elem.newWindow = this;
  20. }
  21.  
  22. // method to make a new window
  23. NewWindow.prototype.open = function()
  24. {
  25.     var href = this.href;
  26.     // prevent normal href execution
  27.     this.href = "";
  28.     // open new window
  29.     window.open(href, this.newWindow.name, this.newWindow.properties());
  30. }
  31.  
  32. // some more methods …
  33.  
  34. // how to use:
  35.  
  36. // create object
  37. var link = document.getElementById("test");
  38. var win = new NewWindow("boogle", 800, 600, link);
  39. // add some properties …
  40.  
  41. // attach event
  42. link.addEvent("click", win.open, false);
Jan 12 '10 #4
jeddiki
290 Contributor
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 ?

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("test").addEvent("click", function() { newWindow(…)}, false);
You said I need to rewrite the newWindow ???
Jan 12 '10 #5
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
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("test").setupWindow({name: "boogle", width: 800, height: 600, scrollbars: "yes" });
Jan 12 '10 #6
Dormilich
8,658 Recognized Expert Moderator Expert
I ended up with an implementation of Element.setupWi ndow() that barely takes up 40 lines…
Jan 12 '10 #7
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:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://www.example.com/code.js">
  2. </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:
Expand|Select|Wrap|Line Numbers
  1. document.onmouseover=hidestatus;
  2. 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.
Jan 15 '10 #8
jeddiki
290 Contributor
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.

Expand|Select|Wrap|Line Numbers
  1. var win=null;
  2. function NewWindow(mypage,myname){
  3. settings='width=850,height=500,top=200,left=50,scrollbars=yes,location=yes,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
  4. win=window.open(mypage,myname,settings);
  5. if(win.focus){win.focus();}}

HTML:

Expand|Select|Wrap|Line Numbers
  1. <a href=\"http://www.example.com/index.php?key=$sup_cd2\" 
  2. onclick=\"NewWindow(this.href,''); return false\" onfocus=\"this.blur()\" >  
  3. <img src=\"http://www.example.com/image_load.php?id=$sup_cd2\" 
  4. 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 :)
Jan 16 '10 #9
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).
Jan 31 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

54
6544
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...
70
8858
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
2
8634
by: aling | last post by:
What are top-down and bottom-up approach in C++ design? How do you usually use them?
9
10833
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?
4
1305
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
4
995
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
5
3843
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?
0
1162
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...
38
1978
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.
0
8385
marktang
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...
0
8821
Oralloy
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...
0
8602
tracyyun
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...
0
7316
agi2029
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...
0
5632
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();...
0
4150
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...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.