/    Sign up×
Community /Pin to ProfileBookmark

Javascript problem with Firefox 3.0.6

Not sure if this post belongs in PHP or Javascript forum. But it seems a javascrips problem I think.

Using mysql and PHP I am selecting data from a database to display but first I want to invoke a javascript alert box to tell the user that he has been successful. All worked perfectly in all browsers until the recent update to Firefox 3.0.6 – still works perfectly IE, Safari and Opera.

Firefox now gets stuck on a blank page instead of displaying the javascript alert – when I click refresh on the blank page all then work OK. My code looks like this:

[code=php]
// select records from the database table:
mysql_select_db($db) or die (“Unable to get into the database!”);
$query = “SELECT field1, field2, field3 FROM tablename
WHERE field1=’$field1′”;
$result = mysql_query($query) or die
(“MySQL error: $query. ” . mysql_error());
if ($myrow = mysql_fetch_array($result)) {
// If records are found, process the following:
$field1=$myrow[“field1”];
$field2=$myrow[“field2”];
$field3=$myrow[“field3”];
[/code]

<script Language=”JavaScript”>
<!–
var alert_msg = “”; // set as global variable
alert_msg += “Your records have been found and displayed.”;
alert_msg += “nPlease check if the details are correct,”;
// –>

alert(alert_msg);
</script>

[code=php]
}
[/code]

Can anyone please help me to see where my code might be incompatible with Firefox lates release – ir is is a Firefox bug??

Many Thanks, Paul

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@toicontienFeb 21.2009 — <script Language="JavaScript">

<!--

var alert_msg = ""; // set as global variable

alert_msg += "Your records have been found and displayed.";

alert_msg += "nPlease check if the details are correct,";

[B][SIZE="5"]// -->[/SIZE][/B]

alert(alert_msg);

</script>

Maybe the // --> before the alert() is doing it? Shouldn't be. Firefox should just read it as a comment, but try moving the // --> below the alert().
Copy linkTweet thisAlerts:
@paulbauthorFeb 21.2009 — Does not make any differennce !! Any other suggestions?
Copy linkTweet thisAlerts:
@FangFeb 21.2009 — What is the full code; there is no correlation with the php to the JavaScript.
Copy linkTweet thisAlerts:
@paulbauthorFeb 21.2009 — You are correct Fang. What I am trying to do is have the user input his registration number, click on go and then the form retrieves and loads full membership details from a mysql database. Instead of just loading and re-displaying I want to display an alert so that the member must click OK before the page is reloaded and displayed.

To do this I have my PHP code to select the details, then insert the javascript alert, then display the page once the user clicks OK on the alert box. It works fine in all browsers except FF 3.0.6. So the code in my first post is pretty much what I am using and has been working for some time.

Any help would be greatly appreciated!!
Copy linkTweet thisAlerts:
@crh3675Feb 22.2009 — Maybe :

<script type="text/javascript>
Copy linkTweet thisAlerts:
@FangFeb 22.2009 — The JavaScript is not being echoed to the output. The code given would not work in any browser.
Copy linkTweet thisAlerts:
@mj1223Mar 25.2009 — Paul,

We have had a similar page display problem with Firefox 3.0.6 and also Firefox 3.0.7

I have a script that runs in the onload event of the body that I thought was the issue. Basically the script prevents the user from using the back button to change their test answers after they have submitted them.

[CODE]
<body onLoad="if(history.length>0)history.go(+1)">
[/CODE]



The strange thing is in the PC versions it does not always happen like it does in the Mac versions. (Especially mac with intel processor where it happens 100% of the time.)

I am going to make sure that all of the scripts have the type="text/javascript"

attribute in them to eliminate that as the reason they stop the page from loading.
Copy linkTweet thisAlerts:
@toicontienMar 25.2009 — You cannot (or should not) be able to block the "back" button on a browser using JavaScript. You need to prevent people from doing this on the server side by keeping track of which questions have been answered already.
Copy linkTweet thisAlerts:
@mj1223Mar 25.2009 — You cannot (or should not) be able to block the "back" button on a browser using JavaScript. You need to prevent people from doing this on the server side by keeping track of which questions have been answered already.[/QUOTE]


That script has been involved in assessments for over 3 years on production level servers that handle thousands of requests a day. It is not causing the problem. And yes, the SPROC that inserts the answers does keep track of what has been answered and what hasn't.

There was never an issue with any of the browsers until FF 3.0.6 came along.


Some people think they can cheat and will sometimes use the backbutton to get a fresh start on the page. Even though this page loads full screen with no browser buttons as well as the contextmenu (right click), F5, Ctrl and Alt Key combinations being blocked via script. Someone will come along that has something in place that allows something to work that we are trying to prevent.
Copy linkTweet thisAlerts:
@toicontienMar 25.2009 — ... There was never an issue with any of the browsers until FF 3.0.6 came along. ...[/QUOTE]
Firefox might be blocking this behavior now since it can interfere with the user's will to use the browser. Basically, it sounds like Firefox is telling the user, "hey, you're in control and this script is trying to prevent you from viewing the page. We blocked that."

So it's a good thing you keep track of the questions that were answered. I always try to write JavaScript so that it doesn't prevent the user from using or viewing the page, as browsers are getting better at blocking that behavior. If I need to block information from the user, I leave that up to the server side script.
×

Success!

Help @paulb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...