PDA

View Full Version : What does "return false" do?



flipper
Jan 17th, 2007, 03:21 AM
In <a href="1081.html" target="new" onclick="window.open('1081.html','new','width=700,height=540'); return false;"> what does "return false" or "true" do?

Where is there a list of this stuff so I don't have to bother you nice people with dumb questions?

By the way, is there a way to get a NEWLY SIZED popup window for every link (I have lots of differently sized linked images) without java? I am using the above, but it keeps the 700x540 (or whatever size the first popup is) no matter what size the next link is.
http://rufushale.com/stonedesign.html is what I'm talking about, on the portfolio page.

Obolopo
Jan 17th, 2007, 04:15 AM
Looks as if the resizing issue has been fixed to me... As for the return false I don't know.

flipper
Jan 17th, 2007, 04:18 AM
Fixed? Really? Maybe it's a browser thing. I'm using safari. You?

Obolopo
Jan 17th, 2007, 06:33 AM
Mozilla Firefox. (Sorry about the late response.)

felgall
Jan 17th, 2007, 06:39 AM
<a href="1081.html" target="new" onclick="window.open('1081.html','new','width=700,height=540'); return false;">

The main action that this performs is to transfer to 1081.html as instructed by the href=. To stop it doing the main action when the onclick Javascript code is run you return false from the onclick code. If instead you were to return true then it would first run the window.open and then run the href which is targetting the just opened window and so the 1081.html page that was just loaded would be loaded into the window a second time. Had you not specified the same name for the new window in both places you would have ended up with two windows opening.

Arbitrator
Jan 17th, 2007, 12:43 PM
To put it more simply, return false is preventing the default action from occurring; felgall refers to the default action as “main action”. The default action in the case of clicking a hyperlink is that the user is directed to the location specified by the href attribute. Since your script already does this, you want to prevent the default action so that the user doesn’t get directed to the location twice—once for the script and again for the href attribute.

There’s a standardized and specialized equivalent for this usage of return false in the DOM2 Events Specification (http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event-preventDefault) called preventDefault(), but lack of support by Internet Explorer has resulted in it script authors not using it.

Note that when I say “for this usage of” above, it is because preventing default actions is not the only use of return false. I won’t detail the other uses here though.

flipper
Jan 17th, 2007, 05:34 PM
Thanks very much u 3.

I never did put javascript in the page. Maybe that's why popups don't pop up in the specified size?

Is there a way to get a differently sized popup for each differently sized linked image without java?

Or, oo! OR, failing that, is there a way to specify the position of the linked image in the popup window (still without javascript)? Because then I could assign the same width and height to all the popups, and just have the images centered in the popup windows. That way it would at least look a little tidier.

Arbitrator
Jan 17th, 2007, 06:12 PM
I never did put javascript in the page. Maybe that's why popups don't pop up in the specified size?

Is there a way to get a differently sized popup for each differently sized linked image without java?

Or, oo! OR, failing that, is there a way to specify the position of the linked image in the popup window (still without javascript)? Because then I could assign the same width and height to all the popups, and just have the images centered in the popup windows. That way it would at least look a little tidier.You can’t specify the dimensions of a window without JavaScript.

flipper
Jan 17th, 2007, 07:33 PM
Ah. Then without specifying the dimensions of the popup, is it possible to specify the position of an image in a popup window (still, alas, without javascript)?

Arbitrator
Jan 17th, 2007, 08:31 PM
Ah. Then without specifying the dimensions of the popup, is it possible to specify the position of an image in a popup window (still, alas, without javascript)?Assuming that each image is within its own HTML page and that these HTML pages are being called by the pop‐ups, then yes.

flipper
Jan 18th, 2007, 12:48 AM
Forgive my continued brazen stupidity, but how, then, to specify image position?

felgall
Jan 18th, 2007, 02:46 AM
The same way you position anything in a web page - by setting up the appropriate stylesheet entries (normally setting margins, padding, and floats is sufficient to position anything unless you need things to overlap).

flipper
Jan 18th, 2007, 03:03 AM
I see. I thought it would be different because it's a link. Glad to know it's so simple! Thanks very much for your replies!! You have all been so patient and helpful and I am really grateful.