Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11350 (new defect)

Opened 2 months ago

Last modified 1 month ago

[PATCH][TEST] innerHTML makes relative hrefs absolute in IE

Reported by: elvanor Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: major Keywords:
Cc:

Description

Go to

http://www.elvanor.net/test/ie-prototype-readAttributeBug.html

for a demonstration of this bug. Basically using element.readAttribute("href") normally fixes the mess IE does with absolute path, eg it will return the actual path on the href attribute. But with dynamically added elements it does not work, and IE will return the absolute path.

(This is on IE 7 with prototype 1.6.0.2)

Attachments

dynamic_href_test.diff (0.8 kB) - added by kangax on 03/18/08 02:29:11.
ie_innerhtml_link_test.diff (1.6 kB) - added by jdalton on 03/27/08 02:34:43.
unit test for the patch
ie_innerhtml_link_fix.diff (3.2 kB) - added by jdalton on 03/30/08 02:02:44.
Updated patch to fix insert(), replace(), and update() methods

Change History

03/18/08 02:29:11 changed by kangax

  • attachment dynamic_href_test.diff added.

03/18/08 21:44:00 changed by kangax

03/20/08 05:30:44 changed by jdalton

This is one way to get the correct href, but it requiores a loop....

	Event.observe(window, 'load', function(){
	 
	  var element = document.body;
	  var html = '<a id=\'example\' href="../../../../stuff.html">click me</a>';
	  var doc = window.createPopup();
	  
	  doc.document.write(html);
	  var docAs = doc.document.getElementsByTagName('A');
	  
	  element.innerHTML = html;
	  var elAs = element.getElementsByTagName('A');
	  
	  for(var i=0,a; a=elAs[i]; i++){
	  	a.href = docAs[i].getAttribute('href', 2);
	  }
	  
	  alert($('example').href);
	
	});

03/20/08 05:34:53 changed by jdalton

Test above is assumed IE only becuase ofuse of the window.createPopup().
This is a bug with innerHTML in IE. I get around it by using document.write on the popup and then collecting all the links and setting the elements links href's to those of the popup.

(follow-up: ↓ 5 ) 03/26/08 03:32:18 changed by kangax

Another "solution" would be to just leave things as they are and mention this behavior in the docs. Afterall, fixing this nasty IE bug by augmenting #update still leaves #readAttribute broken, when elements are appended to the document using plain old innerHTML.

(in reply to: ↑ 4 ) 03/26/08 12:41:20 changed by jdalton

Replying to kangax:

I don't believe readAttribute() is the problem. This issue is caused by the buggy innerHTML property of IE. Element#update is being used to fix several things with it already including innerHTML of tables and inserting scripts. So this bug just seems to be something else that may need to be fixed with the Element#update. As the fix proves readAttribute works fine, its the innerHTML that is the problem. I would not recommend using plain innerHTML knowing the issues IE has with it, and if some dev decides to then they run the risk of it not working.

03/26/08 12:41:46 changed by jdalton

  • summary changed from readAttribute does not work correctly on IE for dynamically added elements to [PATCH] readAttribute does not work correctly on IE for dynamically added elements.

03/26/08 12:44:55 changed by jdalton

  • summary changed from [PATCH] readAttribute does not work correctly on IE for dynamically added elements to [PATCH] innerHTML makes relative hrefs absolute in IE.

This effects all IE's not just 7

03/26/08 13:04:36 changed by elvanor

I never use myself innerHTML, so for my case fixing update() would be enough...

03/27/08 02:34:43 changed by jdalton

  • attachment ie_innerhtml_link_test.diff added.

unit test for the patch

03/27/08 02:35:20 changed by jdalton

  • summary changed from [PATCH] innerHTML makes relative hrefs absolute in IE to [PATCH][TESTS] innerHTML makes relative hrefs absolute in IE.

03/30/08 02:02:44 changed by jdalton

  • attachment ie_innerhtml_link_fix.diff added.

Updated patch to fix insert(), replace(), and update() methods

04/02/08 16:48:08 changed by jdalton

  • summary changed from [PATCH][TESTS] innerHTML makes relative hrefs absolute in IE to [PATCH][TEST] innerHTML makes relative hrefs absolute in IE.