HTMLImports currentScript in v0.1.4

214 views
Skip to first unread message

ando...@gmail.com

unread,
Jan 28, 2014, 11:09:34 AM1/28/14
to polym...@googlegroups.com
The API docs for HTMLImports says

In a native HTML Imports, document.currentScript.ownerDocument references the import document itself. In the polyfill use document._currentScript.ownerDocument (note the underscore).

Given the changes to HTMLImports in this release, is this still suppose to work in 0.1.4?  

After upgrading to 0.1.4, inside a script tag in my import file document.currentScript is null while document._currentScript is undefined.  

Changing my code to get the doc from HTMLImports.currentScript fixed everything for me.  

Steve Orvell

unread,
Jan 28, 2014, 1:20:24 PM1/28/14
to ando...@gmail.com, polym...@googlegroups.com
The HTMLImports polyfill should ensure that "document._currentScript" is universally available (of course document.currentScript is correct but it's not possible to correctly polyfill so we opt for _currentScript).

I can't seem to reproduce this issue. A test case would be extremely helpful, thanks.


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/b54b3d93-54b8-48d7-8a6c-8239656aaf92%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

ando...@gmail.com

unread,
Jan 28, 2014, 1:54:06 PM1/28/14
to polym...@googlegroups.com, ando...@gmail.com
Here's a basic test.  Create the two following files and bower install polymer 0.1.4.

index.html:
<html>
   
<head>
       
<title>HTML Imports Test</title>
       
<script src="bower_components/platform/platform.js"></script>
       
<link rel="import" href="bower_components/polymer/polymer.html">
       
<link rel="import" href="my-import.html">
   
</head>
   
<body>
        HTML Import Test
<br/><br/>
        These values are captured in the imported script and then displayed here in the parent doc.
<br/><br/>
       
<code>
           
<div><strong>document.currentScript = </strong><span id="noPrefix"></span></div>
           
<div><strong>document._currentScript = </strong><span id="prefixed"></span></div>
           
<div><strong>HTMLImports.currentScript = </strong><span id="htmlImports"></span></div>
       
</code>
   
</body>    
</html>


my-import.html
<script type="text/javascript">
   
var parentDoc = document;
   
   
// Display current script values on parent page
    parentDoc
.getElementById("noPrefix").innerHTML = "" + document.currentScript;
    parentDoc
.getElementById("prefixed").innerHTML = "" + document._currentScript
    parentDoc
.getElementById("htmlImports").innerHTML = "" + HTMLImports.currentScript
</script>
Reply all
Reply to author
Forward
0 new messages