简体   繁体   中英

javascript: Creating a script element for an urbanspoon widget: doesn't load

Background

The urbanspoon reservation widget loads via a script tag. Within the script is one massive document.write that loads all the css and html for the widget. You place the script tags within the html you want the widget to load in(i know...)

Problem

Well, this widget is really slow to load and is blocking the loading of other assets. So in attempts to optimize it a little, i'm trying to inject the script tag into the element only when that particular section is requested. Only problem is that the content is not loading.

As per another SO answer, i'm creating a script tag and then populating it with the necessary parameters.

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'long url';
$("#scriptWrapper").append(script);

Everything injects fine and is correct. Problem is that the script is not successfully injecting the content.

Here's a link showing what is returned by the widget link http://www.urbanspoon.com/b/posts/5191

Any ideas?

Thanks!

或者,您可以尝试jQuery.getScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM