BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

url not render on firefox #147

Closed longXE closed 13 years ago

longXE commented 13 years ago

i have a jquery template:

<div id="test_template"> <img src="${url}" width="31" height="32" alt="" /> ${url} </div> I compile it with this:

test_template = $('#test_template').template(); I render it with this:

$.tmpl(test_template, {url:'hxxp://sstatic.net/stackoverflow/img/sprites.png'}).appendTo('#render_test'); note: hxxp=http

the end result is this:

<div id="render_test"> <img height="32" width="31" alt="" src="$%7Burl%7D"> http://sstatic.net/stackoverflow/img/sprites.png </div>

the src or href attribute always return the wrong url

this issue occus in firefox 3.x -> 4.x with the template content places in a div tag, but not when the template places in the script tag. the above code run well on chrome in both template places in script or div as well.

BorisMoore commented 13 years ago

Wrapping in a div is not recommended. Firefox will actually create an img element, and may modify the src attribute, so it will no longer be "${srcUrl}". Wrapping in a script block ensures the browser does not validate or modify the markup (which may not be valid or even well-formed).

longXE commented 13 years ago

yes, it is clear now. thank you for your reply.