473,498 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what's wrong with this code?

Hi,

Does anybody know what's wrong with the following code:

<div align="center"><a href="flashplay.php"
onclick="NewWindow(this.href,'Listen
this!','280','280','no','random');return false" onfocus="this.blur()"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image20','','gifs/mp3_1.gif',1)"><img
src="gifs/mp3.gif" name="Image20" width="125" height="38"
border="0"></a></div>

The intention is this: when someone click on a rollover image, a new window
pop's up displaying the flashplay.php 280x280px page, but for some reason it
doesn't work...If anyone knows a solution, I'd appreciate it a lot.

Dec 9 '05 #1
7 1234
We'd need to see the source code to your "NewWindow" function before
anyone can help. But also 1) are you blocking popups and 2) are you
sure you should even be using popups? Most people I know block them.

Dec 9 '05 #2

<un***********@gmail.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
We'd need to see the source code to your "NewWindow" function before
anyone can help. But also 1) are you blocking popups and 2) are you
sure you should even be using popups? Most people I know block them.


Sorry, my bad.

The source code included in the <head> tag is as follows:

<script language="javascript" type="text/javascript">
<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math .floor(Math.random()*(scre
en.width-w)):100;TopPosition=(screen.height)?Math.floor(Mat h.random()*((scre
en.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(scr een.width-w)/2:100;TopPosi
tion=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") ||
pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPositi on+',left='+LeftPosition+'
,scrollbars='+scroll+',location=no,directories=no, status=no,menubar=no,toolb
ar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script>

Regarding the issues 1) and 2) - no, I'm not blocking pop-ups and 2)I am
sure I want to use popups. Not that I like them, but I have my objective
reasons.
Dec 9 '05 #3
seeker wrote:
The source code included in the <head> tag is as follows:

<script language="javascript" type="text/javascript">
<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random" {LeftPosition=(screen.width)?Math.floor(Math.rando m()*(scre en.width-w)):100;TopPosition=(screen.height)?Math.floor(Mat h.random()*((scre en.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width) (screen.width-w)/2:100;TopPosi tion=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") ||
pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPositi on+',left='+LeftPosition+' ,scrollbars='+scroll+',location=no,directories=no, status=no,menubar=no,toolb
ar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script>


That code is utter nonsense. Do not use it.
PointedEars
Dec 9 '05 #4
On 09/12/2005 14:30, seeker wrote:

[snip]
<script language="javascript" type="text/javascript">
<!--
The language attribute is deprecated and redundant, and the SGML
comments are unnecessary, too.
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math .floor(Math.random()*(scre
en.width-w)):100;TopPosition=(screen.height)?Math.floor(Mat h.random()*((scre
en.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(scr een.width-w)/2:100;TopPosi
tion=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") ||
pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPositi on+',left='+LeftPosition+'
,scrollbars='+scroll+',location=no,directories=no, status=no,menubar=no,toolb
ar=no,resizable=no';
win=window.open(mypage,myname,settings);}


The code you have there is horrid. The following is better:

function createChromelessWindow(uri, name, width,
height, centre)
{
var features = 'resizable,scrollbars',
popup;

if(('function' == typeof window.open)
|| ('object' == typeof window.open))
{
if(!isNaN(width) && !isNaN(height)) {
features += ',width=' + width + ',height=' + height;

if(centre && ('object' == typeof screen)
&& !isNaN(screen.height)
&& !isNaN(screen.width))
{
features += ',left=' + ((screen.width - width) / 2)
+ ',top=' + ((screen.height - height) / 2);
}
}
popup = window.open(uri, name, features);
}
return (popup && (window != popup)) ? popup : null;
}

The random placement feature has been removed as it's a stupid idea, and
centring is controlled via an (optional) boolean. Scrollbars and
resizing are enabled as there is /never/ a reason not allow them.
Finally, rather than assigning the reference to the popup to a global
variable, the reference is returned.

[snip]

All that said, it has nothing to do with your problem. That is almost
certainly caused because of the name you tried to give the new window.
The use of 'Listen this!' is a very bad idea. The name should be
restricted to alphanumeric characters only, contain no spaces,
punctuation or other characters, and must begin with a letter. Something
simpler like 'flashplayer' (based on your URI) would be far better.

<a href="flashplay.php" target="flashplayer"
onclick="return !createChromelessWindow(this.href,
this.target, 280, 280);"
...>...</a>

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 9 '05 #5
Michael Winter wrote:
The code you have there is horrid. The following is better:

function createChromelessWindow(uri, name, width,
height, centre)
{
var features = 'resizable,scrollbars',
popup;

if(('function' == typeof window.open)
|| ('object' == typeof window.open))
{
[...]
popup = window.open(uri, name, features);
}
return (popup && (window != popup)) ? popup : null;
IMO `window' can only refer to the same object as `popup' if the value of
`name' is the name of the current window. Why would you want to return
`null' then, as if creating the popup failed? It did not really fail,
the location of the target window was replaced with the value of `uri'.
}

The random placement feature has been removed as it's a stupid idea, and
centring is controlled via an (optional) boolean.


I have that boolean in my window.js as well because it was written before
I realized that "center" does not necessarily mean the center of one screen.
(Thanks to kind people in de.comp.lang.javascript and here that provided
photos.)

Especially, it has been reported here that IE always returns the values for
the primary display, while Firefox returns the values for the screen the
(left top corner of the) accessing window is located in.

I have the general use of that argument marked as deprecated since then.
PointedEars
Dec 9 '05 #6
On 09/12/2005 17:46, Thomas 'PointedEars' Lahn wrote:
Michael Winter wrote:
[snip]
return (popup && (window != popup)) ? popup : null;


IMO `window' can only refer to the same object as `popup' if the value of
`name' is the name of the current window.


That wasn't something that I had considered.
Why would you want to return `null' then, as if creating the popup failed?


It is one known pop-up blocking technique to return a reference to the
current window, as in:

window.open = function() {
return window;
};

Though I had no intention of trying to detect failure in general
(impossible anyway), I thought it beneficial to cope with some of the
more simple circumstances.

The code should revert to the initial version: the popup variable should
be removed, the return statement (as it currently is) should also be
removed, and the assignment to 'popup' should become a return statement.

[snip]
The random placement feature has been removed as it's a stupid
idea, and centring is controlled via an (optional) boolean.


I have that boolean in my window.js as well because it was written before
I realized that "center" does not necessarily mean the center of one screen.


I realise that, too. However, I let it remain as a 'less stupid' feature
from the original code.

I am of the opinion that the window manager should be left to its job,
and would personally never attempt to centre a pop-up. I'd rarely use a
pop-up, full stop, but that's a different matter. ;)

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 9 '05 #7
On 2005-12-09, seeker <so*****@somewhere.com> wrote:
Hi,

Does anybody know what's wrong with the following code:

<div align="center"><a href="flashplay.php"
onclick="NewWindow(this.href,'Listen
this!','280','280','no','random');return false" onfocus="this.blur()"
onMouseOut="MM_swapImgRestore()"
onMouseOver="MM_swapImage('Image20','','gifs/mp3_1.gif',1)"><img
src="gifs/mp3.gif" name="Image20" width="125" height="38"
border="0"></a></div>

The intention is this: when someone click on a rollover image, a new window
pop's up displaying the flashplay.php 280x280px page, but for some reason it
doesn't work...If anyone knows a solution, I'd appreciate it a lot.


what's the purpose of onfocus="this.blur()"


--

Bye.
Jasen
Dec 9 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
14534
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
5733
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
9898
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
13286
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
46
4152
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
4996
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
1454
by: GS | last post by:
I got a combobox box that I load at load time. the Item and vales ended up in reverse order of each other, what went wrong? the database table has the following row code value ebay ...
98
4485
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
9
2107
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
20
2793
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
0
7125
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,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
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...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
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...
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.