p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Web Programming > JavaScript > Javascript
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 20th, 2009, 09:15 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default dynamically loaded scripts

This is a post which has torture the community very much.

I have AJAX loaded XHTML with scripts:
- External, as <script src="..." />
- Internal, as <script>alert(1);</script>
- As action on events: <a href="" onclick="alert(5); return false;">whow!</a>

IE is not W3C compliant browser so I don't care to support it.

Opera works without any additional work. Scripts running when AJAX loading completes. :)

Firefox works:
- On external with code below (create a <script> element and append on <head> element) :eek:
- On internal with code below (eval) :eek:
- As action on events, without any additional work. :)

Webkit (Safari/Chrome) works:
- On external with code below (create a <script> element and append on <head> element) :eek:
- On internal with code below (eval) :eek:
- As action on events, doesn't work at all :(

So, these questions:
- What I can do to eval() element's event's script on Webkit (Safari/Chrome)? (like <a href="" onclick="alert(5); return false;">whow!</a>)
- Is there a schedule for Firefox and Webkit to automatically load and eval dynamically loaded scripts with AJAX, exactly like Opera?

the code: (innerDOM is the function)
Code:
// create element 'tag'
// add attributes from 'attr' array: [ [ 'attribute1', 'value1' ], [ 'attribute2', 'value2' ] ]
// add contents from 'content' array: [ 'a string', ELEMENT, 5 ]
// append it to 'owner' element
function createTag(tag, content, owner, attr) {
	var t = document.createElement(tag);
	if (attr instanceof Array)
		for (var z = 0; z < attr.length; z++)
			t.setAttribute(attr[z][0], attr[z][1]);
	if (content instanceof Array)
		for(var z = 0; z != content.length; z++)
			if (typeof(content[z]) == 'string' || typeof(content[z]) == 'number')
				t.appendChild(document.createTextNode(content[z]));
			else t.appendChild(content[z]);
	if (owner) owner.appendChild(t);
	return t;
}

// insert 'root' xml tree to 'where' element
function innerDOM(where, root) {
	for (var z = 0; z < root.childNodes.length; z++)
		where.appendChild(root.childNodes[z].cloneNode(true));

	var scripts = where.getElementsByTagName("script");
	for (v in scripts) {
		if (scripts[v].getAttribute('src'))
			createTag('script', null, document.getElementsByTagName("head")[0], [['type', 'text/javascript'], ['src', scripts[v].getAttribute('src')]]);
		else eval(scripts[v].text);
	}
}

Last edited by chameleon : September 20th, 2009 at 09:18 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 28th, 2009, 04:05 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Ok, it is a known Webkit bug.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically changing the <object> element's loaded content codeexploiter BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800 3 October 5th, 2009 09:14 AM
Problem with dynamically loaded user control CodeBest ASP.NET 2.0 Basics 0 February 7th, 2009 09:42 AM
Page Loaded in Seconds Scripts hcweb Classic ASP Basics 8 February 25th, 2004 09:58 PM
Dynamically loaded user conrol vishnu_reddy_n ASP.NET 1.1 1 October 14th, 2003 09:47 AM
How can i know that a form is loaded. sharma_atin VB How-To 1 September 1st, 2003 11:51 AM



All times are GMT -4. The time now is 06:38 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc