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

Safari Javascript Problem

P: n/a
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=45 0,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

Oct 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
da****@passion8.co.uk 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=45 0,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.
--
David Junger

Oct 17 '06 #2

P: n/a
da****@passion8.co.uk wrote:
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=45 0,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 +"'>"
+ "</form></body></html>"
);
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.
--
Rob

Oct 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.