views:

80

answers:

2

Hello, I am trying to make a bookmarklet test. Below code works on FireFox but couldn't on Safari 4.0.3. Does anybody know how to make it work on Safari?

javascript:var s = document.createElement("script");
s.text = "document.write('hello');";
s.type = "text/javascript";
document.body.appendChild(s);
A: 

Try with: s.innerHTML = "document.write('hello');";

Mic
Thank you but it didn't work.
jozei
Strange it works on mine Version 4.0.4 (5531.21.10)
Mic
You place the script tag in the body right?
Mic
jozei
A: 

You need to add document.close() after document.write(...);

javascript:(function(){
  s=document.createElement("script");
  s.type="text/javascript";s.text="document.write('Hello88');document.close();"
  document.body.appendChild(s);
 })();
portoalet
Thanks. But situation is same. I tried below, but it didn't work too.javascript:s=document.createElement("script");s.type="text/javascript";s.text="document.write('Hello88');document.close();" ;document.body.appendChild(s);
jozei
I missed the closing curly brace after document.close();It works on my Safari 4.0.3 OSX
portoalet
Portoalet ,thank you. I already found that thing(and need to add semicolon) but situation is same as bookmarklet.
jozei