Forum Moderators: open

Message Too Old, No Replies

Refining a pop-up script

continued from the HTML forum

         

tedster

7:35 pm on May 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This conversation began in the HTML forum [webmasterworld.com], but now is firmly in the javascript camp.

I had refered smokeyb to msg#4 in the Generic Javascript [webmasterworld.com] thread. He continues in the following post.

Note there are lots of other goodies in that thread as well
It's part of the Javascript Forum Library [webmasterworld.com].

smokeyb

6:19 pm on May 22, 2004 (gmt 0)

10+ Year Member



Thanks tedster. I am however messing about with some code I got from a site that did what I needed. This is a mock up page I've done to test the bit of code
<html>
<head>
<title>Catalogue</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script
type="text/javascript"
language="JavaScript">
<!--
function popUp(theURL,features) {
props=window.open(theURL, 'poppage', features);
props.document.write("<HTML><HEAD><TITLE>Painting View<\/TITLE><\/HEAD><BODY>");
props.document.write("<IMG SRC=\""+theURL+"\">");
props.document.write("<\/BODY><\/HTML>");
}
//-->
</script>
</head>

<body>
<a href=
"JavaScript:popUp('full/02.jpg','width=520,height=520,resizable=no,scrollbars=no,status=no, menubar=no')"> <img alt="View the painting" src="80s/02.jpg" width="80" height="63" border="0"></a>
</body>
</html>[


I am afraid I'm js illiterate (nearly) so I'm not sure if any of the code is superfluous? But when I added the code you suggest in the other post you mentioned, to get the window to open on top, the opposite thing happened? Finally, can I get the closing method you also suggested to work with this, with "close" text in the window along with the image?
Any help is appreciated.

MichaelBluejay

9:36 pm on May 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, the last three lines of your function are redundant. All you need for your function is this:

function popUp(theURL,features) {
props=window.open(theURL, 'poppage', features);
}

Also, I suggest using single quotes (') instead of double quotes (") when using document.write. That way you can use double quotes inside the string to your heart's content. For example:

document.write('<HTML><BODY style="border:0px">Hello</BODY></HTML>')

The only thing you have to escape with a backslash is apostrophes. For example:

document.write('<HTML><BODY style="border:0px">Hello, y\'all.</BODY></HTML>')

Hope this helps.

Rambo Tribble

1:59 am on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, the "theURL" variable appears to be the URL for an image, so the lines with "props.document.write()" aren't exactly redundant; they are creating an HTML document with an image in it, whereas the use of the variable in the "window.open()" command creates just a window with an image in it (no HTML document).

The fact is, the document.write()'s overwrite the initial display of the image and replace it with the document. There would be little noticeable difference in the displayed result. Perhaps some browsers would use different default margins on the bare image vs. the HTML page.

When using document.write(), you should finish with document.close(), otherwise the window will never finish loading.

[edited by: Rambo_Tribble at 2:14 am (utc) on May 23, 2004]

MichaelBluejay

2:11 am on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, that's why the props.document.write statements are redundant -- they write an image that's already there.

Rambo Tribble

2:18 am on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Redundant in the visible effect, yes, but not exactly redundant in the product they create. More could be added in terms of content to the HTML document, through additional document.write() commands. Nothing could be added to the simple image display without modifying the original image.

True redundancy would be if the URL in the window.open() loaded a page with the same markup that the document.write()'s produce.

Perhaps it would be more precise to say for the effect produced, the lines in question are superfluous.

MichaelBluejay

2:51 am on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The <props.document.write> commands are definitely redundant in the truest sense of the word: They do something that's already been done.

The webmaster can load the image with either the <window.open> command *OR* with the <props.document.write> command. There is no need to do both.

The advantage of doing it the latter way is that more HTML code can be added (e.g., a directive to the user to how to close the window, code that closes the window if the user clicks the image, etc.).

The advantage of doing it the former way is that it's simple.

It's up to the webmaster which to choose, but the best choice is either one, not both.

Rambo Tribble

4:09 am on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



While it may (or may not) be valid to argue that it is splitting hairs, is not true that the latter code duplicates the former. An HTML document with an image is not just an image. By the same token, a <span> with a display:block; rule is not a <div>. The effect is qualitatively similar, but the one will continue to validate as an inline element while the other is intrinsicly a block element.

The important point here is to provide a thorough and understandable explanation to the original inquirer as to what the code is doing and why. Hopefully that goal has been accomplished and this thread can be put to bed.

smokeyb

6:49 pm on May 23, 2004 (gmt 0)

10+ Year Member



Thanks all for the input. Unfortunately neither of the questions I asked have been addressed. This is probably because it's history was originally in a different forum. The code I supplied, whether it has redundant bits or not, works fine for opening the image how I want. The problem was: the onBlur bit that tedster offered in his "generic" post. When I added it and tested it, instead of the pic opening on top, it spawned and shot behind the parent page? I was trying to figure out if the superfluous code caused this error? The other thing tedster mentioned was about adding a link for the user to close the spawned window, albeit the entire image... gotta admit that as I didn't use his original example, I couldn't figure how the code should look with this feature added, hence the last part of my post at the top of this thread. I have now actually decided to have the pic open in the site page, and add a link going back to the catalogue. I was less of a headache all round, but I would like to learn this method correctly for possible use in the future.
Thanks for any help

MichaelBluejay

1:04 am on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Smokey, I don't see where you explained *what* you want your code to accomplish with onblur, and I don't see the code itself that contains onblur. It's kind of hard to help when we don't have either, much less when we don't have both.

Rambo Tribble

2:06 am on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The disappearance of the window means it lost focus. As soon as focus is returned to the main page, it will subordinate the window you have opened and, unless the window lies in a portion of the screen not used by the main page, it will be placed behind it.

To close the window in your example, the code would be something like:
props.close();

Don't confuse the window.close() method above with the window.document.close() method mentioned earlier. The former will close the window, while the latter finishes the process of writting to the window.

smokeyb

1:12 pm on May 24, 2004 (gmt 0)

10+ Year Member



Sorry Geez
At the top of this thread you will see that tedster mentions msg 4 in a thread that explained my original question, that is also linked. If you read it, you will see what he suggests for opening the image on top, and how to have it closed by the user. I simply wanted to know what the code I submitted would look like, if I incorporated those 2 things. I had tried, as I have already mentioned, that adding the onBlur command had not worked correc... blah blah blah. I know the reason this post has become complicated, is because it was moved (my fault tedster) but you may have to read between the lines to make sense of it.
Thanks anyway
PS. sorry did'nt see your post rambo