开发者

Use included javascript from external page

开发者 https://www.devze.com 2023-03-26 08:26 出处:网络
What I am trying to do, is display an external page, change the css, and display it to the user, with Jquery/javascript+phonegap. However, if the external page has script tags, which include .js files

What I am trying to do, is display an external page, change the css, and display it to the user, with Jquery/javascript+phonegap. However, if the external page has script tags, which include .js files, then they are excluded, because, I need to modify and save the html locally, then display it again.

Is there a way or is it even possible to include the referenced .js files in the saved external html? I know there are reasons for not allowing to save those files locally, but I only need to use them, not read the contents. I know I can modify the head element to include 'public' .js files,开发者_JAVA百科 such as jquery, but how about 'private' .js files?


The jQuery get() method is useful here. With no argument, it returns all matches in an array. Testing on the W3Schools site seems to reveal this behavior, and, jQuery being a library, I would expect this is not browser dependent.

http://www.w3schools.com/jquery/misc_get.asp

You could use

$("script").get()

to find all script tags. You could even use

$("script").get().filter(function(x){return x.src})
  .map(function(x){return x.src}

Even better is

$("script[src]").get().map(function(x){return x.href})

jQuery is a good example of language extension.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号