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

Safari doesn't execute <script> tags added using the DOM

P: n/a
Here's my situation. I have a function defined in my document's <head>
section which adds a <script> tag to a specified <div> tag. The added
<script> has a src="" attribute pointing to a PHP file, which
dynamically returns JavaScript. In Safari, the src file isn't
downloaded. Neither is any code contained within the new script tag
[such as alert()]. In IE(6) and Firefox, this works as expected.
Here's my code. I hope it will better illustrate what I'm trying to
accomplish:
-------------------
[usage]

<div id="123456">
<a href="#" onclick="add_detail('123456')">Click me</a>
</div>

[in <head>]

function add_detail(divID) {
detail = document.getElementById(divID);
new_script = document.createElement('script');
new_script.setAttribute('src', 'get_details.php?id='+divID);
document.getElementById(occID).appendChild(new_scr ipt);
}

[get_details.php]
(returns dynamically generated javascript code for inserting text
through the DOM... is dependant on the 'id' variable in query string)
-------------------
My goal with this code is to selectively, dynamically receive text and
add it to the document tree without leaving or refreshing the page. I
chose not to load all of the text because it uses web services and
would be a heavy load, as each page has about 50-100 of the above
'Click me' links.

Either a solution to make this work in Safari, or a new method would
be greatly appreciated. Thanks in advance!
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
MPennig wrote:
Here's my situation. I have a function defined in my document's <head>
section which adds a <script> tag to a specified <div> tag. The added
<script> has a src="" attribute pointing to a PHP file, which
dynamically returns JavaScript. In Safari, the src file isn't
downloaded. Neither is any code contained within the new script tag
[such as alert()]. In IE(6) and Firefox, this works as expected.
Here's my code. I hope it will better illustrate what I'm trying to
accomplish:
-------------------
[usage]

<div id="123456">
<a href="#" onclick="add_detail('123456')">Click me</a>
</div>

[in <head>]

function add_detail(divID) {
detail = document.getElementById(divID);
new_script = document.createElement('script');
new_script.setAttribute('src', 'get_details.php?id='+divID);
Why not:
new_script.src="get_details.php?id="+divID;
?
Mick
document.getElementById(occID).appendChild(new_scr ipt);
}

[get_details.php]
(returns dynamically generated javascript code for inserting text
through the DOM... is dependant on the 'id' variable in query string)
-------------------
My goal with this code is to selectively, dynamically receive text and
add it to the document tree without leaving or refreshing the page. I
chose not to load all of the text because it uses web services and
would be a heavy load, as each page has about 50-100 of the above
'Click me' links.

Either a solution to make this work in Safari, or a new method would
be greatly appreciated. Thanks in advance!

Jul 23 '05 #2

P: n/a
What's the difference between doing that and using the DOM function?
Whatever the case, I tried both just now, and there was no change.
Safari is still broken.

Jul 23 '05 #3

P: n/a
On 3 Dec 2004 15:17:46 -0800, pe****@gmail.com wrote:
What's the difference between doing that and using the DOM function?
Whatever the case, I tried both just now, and there was no change.
Safari is still broken.


Actually not, the HTML specification is completely underspecified in
this area, so it has no requirement to execute scripts in that
situation, it's quite a tricky thing to specify, especially once you
introduce the defer attribute.

Anyway, I would advise creating an IFRAME, which is much more
reliable, and have the scripts in that add themselves to the parent
windows scope. I'd only do any of this if you really, really need to
do script loading, is there really a sound reason too?

Jim.
Jul 23 '05 #4

P: n/a
http://jibbering.com/2002/4/httprequest.html

I just found out about this! This is essentially what I was trying to
simulate. A JS-initiated HTTP request. I think I'll try this out and
see what happens.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.