Forum Moderators: coopster

Message Too Old, No Replies

The Madwocky 'Close' button

Is there a Moses in the house? I have a sea to part...

         

Josefu

3:07 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



This is my first time posting here as I've been a die-hard PHP programmer since... a week now.

I've almost completed the switchover to .php and have already set up my mysql server and database and tables and such and all the images/info/etc is entering nicely into my server-generated pages but... there is ONE thing that won't work - a maudit 'close' button. The 'javascript:window.close();' shows up when I click... click... clickclickclickclick but the window won't close.

I have stripped the whole page away, most all PHP inserts and everything, and I've narrowed it down to these lines: if I take either line away the window will close but with both - nyet. I also noticed that if I bookmarked a page with a query in the url the window won't close either. Here I stripped away the error-stoppers for clarity...

#I leave this one and take away the '$product_number=mysql...' line javascript works. Take away this one and leave the other it works as well.
$idItem=$_GET['item'];

# the below seems fine but here for reference
$result = mysql_query("SELECT * FROM my_table WHERE product_number = '$idItem'")

#this is just the first line of around ten var-setters like this - if there is even but one the javascript no longer works.
$product_number=mysql_result($result,"my_table","product_number");
...

Oh, and there's a space in the product number... a model is 'BAB 1-01' (no quotes) - I wanted to fix that but I read that php and the browser encode and decode that space without any problem.

On last important thing: there's two (forward and back) arrows which will take the viewer to the adjascent products (BAB 1-02 etc...) - all I did was put a <?php insert into the 'onClick' url (to the same page) which would add '?item=BAB 1-01' on to the end - like a refresh but with a new query.

This has been long - but how I go wrong?

I'll probably be slapping my forhead by the week's end but for now I would appreciate any input at all - especially about what one can or can't put on a PHP page.

Oh, and the funniest thing: I don't have the above problem in IE 6.0 or IE 5.5 for Mac - works just fine. I am not a happy boy if things don't fly in all browsers though - especially Safari, Mozilla and Netscape.

Thanks in advance,

Josefu

HelenDev

3:24 pm on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$result = mysql_query("SELECT * FROM my_table WHERE product_number = '$idItem'")

are you missing a ; of the end of this line or is it just a typo in your post?

Josefu

3:34 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



Wow, that's a fast reply! Was just off for a nap but this problem is serious for me...

The above has been stripped down from:

"if (! @$result = mysql_query("SELECT * FROM my_table WHERE product_number = '$idItem'")) {
header("Refresh: 2; URL=http://localhost/");
echo '';
exit();}"

...I just tried another thing though and the results are odd... That 'stripped' page I mentioned earlier - I took EVERYTHING away but the close button (ALL the php and javascript page refs) and the page closed fine - but when I hit a bookmark to that same stripped page I had made earlier with the query in the URL ('/mypage.php?item=BAB%201-01') the javascript wasn't working again. I have found no documentation on this at all... a bug or just rare stupidity? Anyhow thanks for your reply.

httpwebwitch

5:02 pm on Jun 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



header("Refresh: 2; URL=http://localhost/");

Remember that PHP does not cause javascript errors; it is the OUTPUT from PHP which may have javascript errors. Instead of working from the code to the source, open the HTML source and find out why the javascript is erroring (is that a word?).

Once you know how to fix the javascript error, then it's easier to adjust your PHP code so it outputs the right stuff.

The code above is strange - that is the syntax used in a <meta> tag for refreshing/redirecting. That's the method you want if you desire the redirection to be triggered from the browser.

A redirection using PHP's header() looks like this:
header("Location:http://localhost/index.php");

Josefu

5:15 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



Thanks for your reply.

Yes, that header is a little odd, isn't it? I'll fix it - but it doesn't seem to be the problem.

You know what I just did? I took the source code from the page PHP generated and created a new document with it - just the 'close' button. Again, it closes fine with just the URL - but again if I try to open the same page with a query (in fact any one at all) the javascript won't work anymore. Odd, no? That narrows it down to the URL query - not being answered? Odd odd odd...

Josefu

6:33 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



If I can add to this problem without making a sketch of it: I went ahead all the same and started linking my 'page openers' complete with queries in the URL to the corresponding database-generated pages... all close fine.

My conclusion to this story is, that in case of a page 'error' (unanswerable or no query (because in the code I ask for it), the page somehow 'blocks'... therefore I must do an 'or' statement allowing for a 'naked' or erronous URL coming from... for example an outdated link.

I would really like an explanation as to why 'unanswered' or erronous php would block the page process... namely for Mozilla and Gecko browsers. Anyone out there in the know? Also, if I missed the mark, please feel free to correct me.

Thanks again again,

Josefu.

caspita

6:42 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



Hi Josefu,

As httpwebwitch said before .. php should not make your javascript fail.. it is something in the php output. Have you noticed for example opening your page with IE if the little yellow tringle at the bottom-left pops-up? that will indicate a sysntax error (or some error) in the javascript code, browser can be configured to show furter.. number of line or so.. then you can see the 'real' error. As you said it could be the resoult of you query that is being dumped to the html code, some odd character .. you may want to use htmlentities() php function that will wrap every html tag that is in an string and you want to print out.

I hope this helps,

CS.

Josefu

7:02 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



LOL I'm still at it. Thank you.

I understand about the 'server-side' aspects of PHP and mySql - I'm really beginning to dig what it CAN do - like updating catalogs from simple text files (which even my wife is capable of filling in - fill in the columns) - it's just this problem that falls outside of what I've learned (so far).

A php page (eg 'index.php') virgin but for one javascript 'close' button will no longer close by that button if it is adressed by a query that ends up as NULL. Even if there is no other javascript or php on the page. Or in other words: a page labelled '.php' with no php on it, when addressed by a php query, will answer 'null' and somehow block the javascript process. Perhaps it is just my testing server (on my computer)?

Josefu

6:34 am on Jun 25, 2004 (gmt 0)

10+ Year Member



Yawn! (rubbing eyes) Waking up this morning I see that my question doth stir nary a reply... I'll get on it again today and post the answer if I find it. Today's reading: 'Error trapping'...