By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,709 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,709 IT Pros & Developers. It's quick & easy.

Mouse shape after opening a new window and closing it

P: n/a
All,
I have a printer friendly page that is opened when a user clicks a link on
my page to get the printer friendly version,
How ever when they close out the printer friendly version and return to the
original page the mouse cursor is a Hour glass shape!
my code:

I use DIV tag
<DIV id ="printThis">
<%
response.write strTable
%>
</DIV>
<A HREF ="javascript:void(printFriendly())">Print This Page</A>

the javascript function printFriendly is:
function printFriendly()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';
html += '\n</HEAD>\n<BODY>';
var printFriend = document.getElementById("printThis");
if (printFriend != null)
{
html += printFriend.innerHTML;
}
else
{
alert("Could not find any thing to print");
return;
}
html += '\n</BODY>\n</HTML>';
var printWin = window.open("","Printer Friendly");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
}
else
{
alert("Sorry, the print ready feature is only available in modern
browsers.");
}
}
-->
</SCRIPT>

What I have seen is that the Mouse shape is effected after returning to the
original page Why? I am not sure but I have noticed that on some browsers
this does not happen and also in my browser the hour glass shape happened 8
out of ten time!

Any ideas why this may happen

Thanks
Jawahar
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Jawahar Rajan" <jr****@nc.rr.com> wrote in message
news:Rd**********************@twister.southeast.rr .com...
<snip>
How ever when they close out the printer friendly version
and return to the original page the mouse cursor is a Hour
glass shape! my code: <snip> <A HREF ="javascript:void(printFriendly())">Print This Page</A>

<snip>

That is one of the many reasons for not using the javascript: pseudo
protocol:-

<URL: http://www.jibbering.com/faq/#FAQ4_24 >

Richard.
Jul 20 '05 #2

P: n/a
DU
Jawahar Rajan wrote:
All,
I have a printer friendly page that is opened when a user clicks a link on
my page to get the printer friendly version,
How ever when they close out the printer friendly version and return to the
original page the mouse cursor is a Hour glass shape!
my code:

I use DIV tag
<DIV id ="printThis">
<%
response.write strTable
%>
</DIV>
<A HREF ="javascript:void(printFriendly())">Print This Page</A>

For *many* reasons that I won't explicit here, do not use the
"javascript:" pseudo-protocol in a href value: that's bad, bound to go
wrong, create problems for the user.
the javascript function printFriendly is:
function printFriendly()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';
html += '\n</HEAD>\n<BODY>';
You need to escape occurences of / & when constructing a string like that.
Your code is somewhat illogical. You interrogate if the user agent
supports the getElementById method and if it does, then why not go ahead
and try to construct that document with DOM level 1 and DOM level 2
methods for creating DOM nodes. I would expect you to resort to
document.write if the user agent would not support getElementById, not
the reverse.
var printFriend = document.getElementById("printThis");
if (printFriend != null)
This if control statement is somewhat redundant: you tested if the user
agent supports getElementById already, so your printFriend variable
should point to the referenced element "printThis". Here, you would
prefer to test the support for innerHTML if you want to use this.
{
html += printFriend.innerHTML;
}
else
{
alert("Could not find any thing to print");
return;
}
html += '\n</BODY>\n</HTML>';
Here, you need to escape the occurences of / within the constructed string:

html += '\n<\/BODY>\n<\/HTML>';

Here, I would watch the html var value with a debugger... just to make
sure of your code.
var printWin = window.open("","Printer Friendly");
The 2nd argument of the window.open() call requires a single string
without blank space.
Strangely enough, NS 6.2+ and Mozilla-based browsers are tolerant of
blank spaces in this 2nd argument of the open() call while MSIE 5+ is
not... but only the Netscape documentation explicitly indicate that
blank spaces are not allowed.

"windowName can contain only alphanumeric or underscore (_) characters."
http://devedge.netscape.com/library/...w.html#1202731

"When opening a window, this is a String that specifies the name of the
window."
http://msdn.microsoft.com/workshop/a...ods/open_1.asp

The single blank space in the "Printer Friendly" could be why you would
get an hour glass in MSIE 6.
printWin.document.open();
This could be related to bug 191377:
window.open("") does not open blank window
http://bugzilla.mozilla.org/show_bug.cgi?id=191377
http://bugzilla.mozilla.org/attachme...38&action=view

Apparently, loading a window and modifying a document tree are 2
different asynchronized processes. That's why sometimes scripts fail
because the WindowObjectReference.document.write() call can not be done
since the loading of the window (with its reference pointer, etc..) is
not completed yet. Overall, people underestimate or ignore the amount of
resources (parsing, rendering, RAM, cpu, video, etc..) required to
create a single new window, an ordinary popup window.

printWin.document.write(html);
printWin.document.close();
}
else
{
alert("Sorry, the print ready feature is only available in modern
browsers.");
}
Right here, you are confirming what I think. If the user agent is a
modern browser, then why not resort to DOM1 and DOM2 methods for
creating DOM nodes instead of document.write and innerHTML?
}
-->
</SCRIPT>

What I have seen is that the Mouse shape is effected after returning to the
original page Why?
The hourglass cursor means that the os is still busy doing something
important: sometimes, it indicates an infinite loop or a memory leak.

I am not sure but I have noticed that on some browsers

You did not say which browser and browser version does have the problem
you describe.
this does not happen and also in my browser the hour glass shape happened 8
out of ten time!

Any ideas why this may happen

Thanks
Jawahar


If we could see a fully coded page for testing, we could pinpoint the
problem. But in the meantime, I can offer 2 acceptable alternatives to
your given code.

1- use a print media stylesheet:
"CSS Beyond the Browser: Going to Print
Say no to 'printer-friendly' versions and yes to printer-specific style
sheets. CSS expert Eric Meyer shows how to conceive and design print
style sheets that automatically format web content for off-screen
delivery. Includes tips on hiding inappropriate content, styling text
for the printer, and displaying the URL of every link on the page."
http://www.alistapart.com/stories/goingtoprint/

2- use createElement() DOM level 1 methods and populate your document in
the popup that way.
E.g.:
http://bugzilla.mozilla.org/attachme...38&action=view

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.