473,763 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript & Firefox: simple code don't executed

10 New Member
Hi all!
I've wrote this code:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.                     var largImg;
  3.                     var altImg;
  4.                     var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il codice HTML ti verrà mostrato in questa pagina e, per comodità, ti verrà inviato, via mail, all\'indirizzo da te fornito. Se invece vuoi cambiare il banner premi "Seleziona banner"';
  5.                     var txtButton = 'Cambia banner';
  6.                     var testo = '';
  7.                     var maxLarg = 450;
  8.                     var maxAlt = 80;
  9.                     var diffLarg;
  10.                     var diffAlt;
  11.                     var diff;
  12.                     function setBanner(url, id){
  13.                         window.opener.document.getElementById("testoReceive").innerHTML = txtTop;
  14.                         window.opener.document.getElementById("bannerSel").value = txtButton;
  15.                         largImg = window.document.getElementById(id).width;//parseInt(url.split("/")[url.split("/").length-1].split("_")[0].split("x")[0]);
  16.  
  17.                         altImg = window.document.getElementById(id).height;//parseInt(url.split("/")[url.split("/").length-1].split("_")[0].split("x")[1]);
  18.  
  19.                         txtLarg = "Larghezza: " + largImg + "px";
  20.                         txtAlt = "Altezza: " + altImg + "px";
  21.                         diff = (largImg - altImg) + Math.abs(largImg - altImg);alert(diff);
  22.                         testo += '<table cellpadding="0" cellspacing="0" width="100%">';alert(1);
  23.                             testo += '<tr>';
  24.                                 testo += '<td valign="middle">';
  25.                                     testo += '<img id="previewBanner" src="' + url + '"/>';
  26.                                 testo += '</td>';
  27.                                 if(diff != 0){
  28.                                     testo += '</tr><tr>';
  29.                                 }
  30.                                 testo += '<td valign="middle">';
  31.                                     testo += txtLarg + '<br/><br/>';
  32.                                     testo += txtAlt;
  33.                                 testo += '</td>';
  34.                             testo += '</tr>';
  35.                         testo += '</table>';
  36.                         window.opener.document.getElementById("divBanner").innerHTML = testo;
  37.                         diffLarg = (largImg - maxLarg) + Math.abs(largImg - maxLarg);
  38.                         diffAlt = (altImg - maxAlt) + Math.abs(altImg - maxAlt);
  39.                         if(diffLarg != 0){
  40.                             if(diffAlt != 0){
  41.                                 var propDiff = (Math.abs(largImg - maxLarg) - Math.abs(altImg - maxAlt)) + Math.abs(Math.abs(largImg - maxLarg) - Math.abs(altImg - maxAlt));
  42.                                 if(propDiff != 0){
  43.                                     window.opener.document.getElementById("previewBanner").style.width = maxLarg + 'px';
  44.                                 }
  45.                                 else{
  46.                                     window.opener.document.getElementById("previewBanner").style.height = maxAlt + 'px';
  47.                                 }
  48.                             }
  49.                             else{
  50.                                 window.opener.document.getElementById("previewBanner").style.width = maxLarg + 'px';
  51.                             }
  52.                         }
  53.                         else{
  54.                             if(diffAlt != 0){
  55.                                 window.opener.document.getElementById("previewBanner").style.width = maxAlt + 'px';
  56.                             }
  57.                             else{
  58.                                 window.opener.document.getElementById("previewBanner").style.width = largImg + 'px';
  59.                                 window.opener.document.getElementById("previewBanner").style.height = altImg + 'px';
  60.                             }
  61.                         }
  62.                             window.close();
  63.                     }
  64.                 </script>
  65.  
It's simple:
1) the caller send an url like "140x257_1. jpg" and an id generated by xsl
2) the function substitute what's in caller page's "testoRecei ve" div with a pre-set variable
3) change the value of a caller page's button
4) get the dimension of the image
5) check which dimension is the higher with a difference. If largImg is higher than altImg, diff will not be 0.
Ex: (5 - 3) + abs(5-3) = 2 + 2 = 4; Ex2: (3 - 5) + abs(3 - 5) = -2 + 2 = 0
6) insert into variable "testo" the HTML code to create a table.
7) use variable testo as HTML of caller page's divBanner div
8) check if the dimensions are higher than a max. If it's, resize the image.
9) set image's width and height.

My problem is: firefox execute the function until "alert(diff )" included. From next istruction don't do anything.
I've tried to remove all table's attribute but nothing change, I've tried to insert <tbody> but nothing.
Someone would help me please?
Thank you.
Dec 15 '07 #1
22 2796
acoder
16,027 Recognized Expert Moderator MVP
Does it not even alert 1 on line 22? What error message do you get?
Dec 17 '07 #2
giordan
10 New Member
The only alert I have is at line 21.
Click here to try.
Pressing "Seleziona banner" ("select banner" translated in english) you have the page. It's an xml page formatted with an xsl stylesheet. The script is inside the xsl code. So if you try to get the source you'll have an xml page.
Click here to have the complete xsl file.

Thank you!
Dec 17 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
In Firefox, I see the error:
window.opener.d ocument.getElem entById("previe wBanner") has no properties
http://www.naera.it/public/xml/bannerNaera.xml
Line 44
Dec 17 '07 #4
giordan
10 New Member
I know. But the problem is that previewBanner is create dinamically by the previous lines. So...what's the problem??? Why previewBanner has no properties??? Why in IE work properly???

I don't see anything strange...
My only thought is that HTML added by Javascript isn't accessible by Javascript...bu t...I hope it's possible...

Or...maybe firefox don't insert HTML code contained in variable "testo" into opener page...but why do not should do that?

Uff...I hate Firefox!!!

Thank you all!
Dec 17 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
I know. But the problem is that previewBanner is create dinamically by the previous lines. So...what's the problem??? Why previewBanner has no properties??? Why in IE work properly???
In Firefox, the code appears like this (with indents):
Expand|Select|Wrap|Line Numbers
  1. testo += '';
  2. testo += '';
  3. testo += '';
  4. testo += '';
  5. testo += '';
  6. if(diff != 0){
  7. testo += '';
  8. }
  9. testo += '';
  10. testo += txtLarg + '';
  11. testo += txtAlt;
  12. testo += '';
  13. testo += '';
  14. testo += '';
No wonder it doesn't work!
Dec 17 '07 #6
drhowarddrfine
7,435 Recognized Expert Expert
In addition, your html contains attributes which do not exist. In one inline styling, you say "stile" instead of "style". Also, id names must be unique to one element on a page. You cannot use them more than once.

In your CSS, you have several properties that begin with a 's' so these do not exist.
Also, the values have no unit, such as px, specified.

Validate your html and css for those lists of errors.
Uff...I hate Firefox!!!
Never, ever use IE as a reference to how things should work. It is 10 years behind web standards, particularly the DOM. It is buggy and incomplete in its implementations . Always use a modern browser, such as Firefox, Opera or Safari to initially test your page. Then check in IE to adjust for its quirks and bugs.
Dec 17 '07 #7
giordan
10 New Member
Guys I've found the problem...
I don't know why but Firefox want that simbols "<" and ">" must be translated with "&lt;" and "&gt;", differently from IE.
In IE, writing &lt; or &gt; show "<" and ">" like no-code simbols.

Mah...Firefox.. .what a strange browser...

Thank you all!
Dec 17 '07 #8
acoder
16,027 Recognized Expert Moderator MVP
Glad you managed to fix the problem.
Mah...Firefox.. .what a strange browser...
Have you tested in Opera, Netscape, Safari and others? You'll find, more often than not, that what doesn't work in Firefox won't work with the rest either.
Dec 17 '07 #9
drhowarddrfine
7,435 Recognized Expert Expert
More appropriately, What works in all browsers most likely won't work in IE because it is non-standard or broken.

I hate to keep preaching that but until people understand that coding to IE is coding to a bug, they will constantly have questions as to why things don't work in the modern browsers.

Again, never, ever, ever use IE as a reference for how anything. should work.
Dec 17 '07 #10

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

Similar topics

0
1458
by: Ronan | last post by:
Hi, I have a problem with a form using the PHP PEAR HTML_QuickForm package & javascript: I want to record the content of my form into a mySQL database then execute a javascript function. My problem is that javascript is executed before the mySQL insertion. I actually need the mySQL insertion first, since my javascript function
38
3537
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
16
3111
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
5
1774
by: Florian Proch | last post by:
Hi all... i'm currently working for a big project to construct a website. We need to support some browser and OS : IE 5.0 -> IE 6, Mozilla 1.2 -> 1.7, Opera 5 -> Opéra 7.5x, Netscape 4.75 -> NS 7.2, Safari and for OS : Win95/98/NT/Me/2000/XP, MacOS 9/10, Linux. I have some problems with browser on different OS. For example i have write a javascript who make a automatic submit when the page is reload.
11
4733
by: Polar | last post by:
Hi! i'm a newbie in C language and i'm writing my first simple codes. In one of these, my purpose is to append the ascii value of an interger (example 101 --> e) at the end of a string to obtain a new (longer) string. Example: string: languag letter: e
2
2842
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added to it to view additional details about the selected result (a second database query is triggered). I want this second query to pop up in a new window, the way it would if I used "window.open" in javascript. I've added a function in the
4
1416
by: sravan_reddy001 | last post by:
I hav a method which is called repeatedly. i want a part of that code to be executed once. this can be possible with the help of ---- if() and a flag ---- is there any other method to do this. That part of code should be present in the method.
3
2422
by: BAnderton | last post by:
Hello all, Question: Is there any way to access a javascript variable from within psp code? I'm aware of how to do the reverse of this (js_var='<%=psp_var%>'). Here's a non-working example of what I'm trying to do:
11
1792
by: shror | last post by:
Hi every body, Please I need your help solving my php mail() function problem that the code is appearing in the view source and I dont know whats the problem where I am using another page tto test the php and its executed very nice The page have php code viewed : http://beachtoursegypt.com/booking-form.htm where after submitting the form the data are sent to the confirmation age where the php script lies there and its not executed
0
10148
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
10002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
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
6643
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
5270
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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 we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
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.