473,480 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
4 2231
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2238
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT...
1
1649
by: JMMB | last post by:
The <script> tags work in a htm page, but when I convert it to .aspx page, it stops working? I get a IE script error. What might be the mistake here? thanks, <HTML> <HEAD> <TITLE> Teste...
1
1441
by: D. Shane Fowlkes | last post by:
I'm a fairly skilled traditional ASP/VB programmer and am learning .NET. I was (recently) surprised to read in a book about declaring and defining all my page Functions in <script...
2
1542
by: Jeffrey T. | last post by:
I had some JavaScript functions defined in the <SCRIPT> section at the top of an aspx page (tested fine there). I then moved the JavaScript functions to their own separate file and then...
21
8483
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript"...
3
1839
by: Jarod_24 | last post by:
My program (it's a webcrawler) downloads htmlpages and in some cases the html has <script> </script> tags in it that generates parts of the html. How can i interpret this javascript and get the...
12
62864
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
44
2789
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
2
2940
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
6
1516
by: xhunter | last post by:
Hi, I am loading a page using ajax, I want to match the content of <script>***</script> tags, and use eval() to evaluate them instead, I tried alot but I couldn't find a proper pattern for a...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7088
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.