ActionsDev

4 replies to this thread. Most Recent

Paul

5 Mar 2019, 9:12 am

Short attributes in tags

Hi, one of my more funky Actions puts a <script> tag in the header, and references an external .js file. Looking at what’s available to this in XHTML and HTML 5, there are some additional attributes that can be added to the tag - async and defer.

However, there are differences between XHTML and HTML 5. In XHTML, the attributes must have a value, so you need (and this is to shop both attributes in play - this may not be necessary):

<script src="javascript.js" type="text/javascript" async="async" defer="defer"></script>

In HTML5, you would type:

<script src="javascript.js" type="text/javascript" async defer></script>

You will notice that you just need the attribute name, NOT the values. I can’t see how to do this in an Action.

So, Action code looks a little like this right now:

 var head = fwDocument.fwTags.fwFind("head",fwPage);
 var myScript = myTag.fwAddOpt("script",true);
 myScript["src"] = fwQuote("javscript.js");
 myScript["type"] = fwQuote("text/javascript");
 myScript["async"]=fwQuote("async");
 myScript["defer"]=fwQuote("defer");

That last line is good for XHTML 5, but how would you just drop in the attribute name without the value. For reasons that are necessary (and good and proper), I obviously want the action to put the tag into the tag tree as it is currently doing, so it’s available for other actions to manipulate (if necessary - and at this it is necessary).

All the best,

Paul

My Actions Site: http://www.actionsworld.com

Actions for Galleries, decorating that text box and many more!

waltd

5 Mar 2019, 2:09 pm

I don’t think you can do the single-value tags in the usual Action tag manipulation method. You could easily convert the tag to text and write it into the output stream with the additional attributes, but then it would not be a tag, and further manipulation by other Actions would be impossible.

It’s important to note that HTML5 allows the single-ended attributes, but does not require them. Almost everything about HTML5 is more lenient than XHTML, but the formal XML-like syntax is valid, too. Try validating a page that uses the “loose” syntax and then the same page with the async=”async” style using the W3C validator.

Walter

On Mar 5, 2019, at 4:12 AM, Paul <[email protected]> wrote:

Hi, one of my more funky Actions puts a <script> tag in the header, and references an external .js file. Looking at what’s available to this in XHTML and HTML 5, there are some additional attributes that can be added to the tag - async and defer.

However, there are differences between XHTML and HTML 5. In XHTML, the attributes must have a value, so you need (and this is to shop both attributes in play - this may not be necessary):

<script src=”javascript.js” type=”text/javascript” async=”async” defer=”defer”></script>

In HTML5, you would type:

<script src=”javascript.js” type=”text/javascript” async defer></script>

You will notice that you just need the attribute name, NOT the values. I can’t see how to do this in an Action.

So, Action code looks a little like this right now:

var head = fwDocument.fwTags.fwFind("head",fwPage);
var myScript = myTag.fwAddOpt("script",true);
myScript["src"] = fwQuote("javscript.js");
myScript["type"] = fwQuote("text/javascript");
myScript["async"]=fwQuote("async");
myScript["defer"]=fwQuote("defer");

That last line is good for XHTML 5, but how would you just drop in the attribute name without the value. For reasons that are necessary (and good and proper), I obviously want the action to put the tag into the tag tree as it is currently doing, so it’s available for other actions to manipulate (if necessary - and at this it is necessary).

Freeway user since 1997

http://www.walterdavisstudio.com

Paul

6 Mar 2019, 2:40 pm

Thanks, Walter. I’ll keep the Action as it is for the moment.

On 5 Mar 2019, 2:09 pm, waltd wrote:

I don’t think you can do the single-value tags in the usual Action tag manipulation method. You could easily convert the tag to text and write it into the output stream with the additional attributes, but then it would not be a tag, and further manipulation by other Actions would be impossible.

It’s important to note that HTML5 allows the single-ended attributes, but does not require them. Almost everything about HTML5 is more lenient than XHTML, but the formal XML-like syntax is valid, too. Try validating a page that uses the “loose” syntax and then the same page with the async=”async” style using the W3C validator.

Walter

On Mar 5, 2019, at 4:12 AM, Paul

All the best,

Paul

My Actions Site: http://www.actionsworld.com

Actions for Galleries, decorating that text box and many more!

Tim Plumb

23 Apr 2019, 5:41 pm

Hi Paul,

I saw this thread earlier today and knew I’d faced this same problem before but just couldn’t locate the Action I was thinking about.

After a bit of testing it appears the solution is to pass an empty string into your attributes;

function fwAfterEndHTML(){
    var head = fwDocument.fwTags.fwFind("head",fwPage);
    var myScript = head.fwAddOpt("script",true);    

    myScript["src"] = fwQuote("javscript.js");
    myScript["type"] = fwQuote("text/javascript");

    myScript["async"] = "";
    myScript["defer"] = "";
}

which gives you;

    <script src="javscript.js" type="text/javascript" async defer></script>

I had thought that setting the fwTitle or fwValue on the attribute to null would do the job.

Tim Plumb - Experienced Freeway designer for hire

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro

Back to Top

Paul

24 Apr 2019, 7:08 pm

Ah, thanks., Tim!

All the best,

Paul

My Actions Site: http://www.actionsworld.com

Actions for Galleries, decorating that text box and many more!