Safari Javascript Problem

D

darren

I have a small Javascript problem with that mutch love web browser
safari, I tested the code on all other browsers PC (Win) and Linux and
IE on the mac and it seams to work ok, but for some reason it will not
work with safari.

function domywindows() {
//alert('test');
mywondows =
window.open('writeme.html','TellAFriend','width=450,height=600');
mywondows.document.write("<html>");
mywondows.document.write("<body>");
mywondows.document.write("Working Please Wait........")
mywondows.document.write("<form method='post' name='myform'
action='sendm.php' target='_self'>");
mywondows.document.write("<input type='hidden' name='urlis' value='" +
window.location + "?osadcampaign=tf'>");
mywondows.document.write("<input type='hidden' name='productname'
value ='" + productname +"'>");
mywondows.document.write("</form>");
mywondows.document.write("</body>");
mywondows.document.write("</html>");
mywondows.document.myform.submit();
}

Any one any ideas how i can make this mac compatable...

TA
 
T

Touffy

(e-mail address removed) said:
I have a small Javascript problem with that mutch love web browser
safari, I tested the code on all other browsers PC (Win) and Linux and
IE on the mac and it seams to work ok, but for some reason it will not
work with safari.

function domywindows() {
//alert('test');
mywondows =
window.open('writeme.html','TellAFriend','width=450,height=600');
mywondows.document.write("<html>");
mywondows.document.write("<body>");
mywondows.document.write("Working Please Wait........")
mywondows.document.write("<form method='post' name='myform'
action='sendm.php' target='_self'>");
mywondows.document.write("<input type='hidden' name='urlis' value='" +
window.location + "?osadcampaign=tf'>");
mywondows.document.write("<input type='hidden' name='productname'
value ='" + productname +"'>");
mywondows.document.write("</form>");
mywondows.document.write("</body>");
mywondows.document.write("</html>");
mywondows.document.myform.submit();
}

Any one any ideas how i can make this mac compatable...

I do have an idea. I don't have time to test it, but here you go:

When you dynamically create a document with document.write(), you
should really call document.close() after you're done document.writing
it. The other browsers may guess somehow (maybe because you call a
method of a child of that document) but you can't blame Safari for not
predicting that you won't document.write() anymore.
Acutally, if you document.write() into that window after calling its
document.myform.submit, all the other browsers will likely start the
document from scratch since they closed() it implicitly, while Safari
may be able to append to it. Which behavior is right, the
specifications don't say.
Add this line right after the last document.write in your function:

mywondows.document.close()

and see if it works better in Safari.
 
R

RobG

I have a small Javascript problem with that mutch love web browser
safari, I tested the code on all other browsers PC (Win) and Linux and
IE on the mac and it seams to work ok, but for some reason it will not
work with safari.

"...will not work" is not a suitable explanation. Does the new window
open? Does anything get written? Do you see any errors in the script
console?
function domywindows() {
//alert('test');
mywondows =
window.open('writeme.html','TellAFriend','width=450,height=600');

Since you completely replace the content of the document, why not leave
the URL blank?

window.open('', ...);

mywondows.document.write("<html>");

Instead of a series of document.write statements, use one statement and
concatenate the text to be written:

mywondows.document.write(
"<html><body>Working Please Wait........"
+ "<form method='post' name='myform' "
+ "action='sendm.php' target='_self'>"
+ "<input type='hidden' name='urlis' value='"
+ window.location + "?osadcampaign=tf'>"
+ "<input type='hidden' name='productname' value ='"
+ productname +"'>"
+ said:
mywondows.document.myform.submit();

Before attempting to access elements in the new document, finish
writing it with document.close(), then try to submit the form:

mywondows.document.close();
mywondows.document.myform.submit();

If you don't close the form, Firefox will also continue to look like it
is loading the document until some other event causes it to stop (like
loading another page).

As a general strategy, it seems pointless to create a new (pop up)
window just to submit a form, particularly as many pop-up blockers can
stop you from doing so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top