0

I have a system of posts, where the publisher can embed code another site to reference content. However, I am having a problem with the LookBook.nu site.

The site of this embedded code contains a script tag that calls jQuery 1.6 and causes my system to crash.

I wanted to remove this script tag with regex. Is this possible?

This is the embedded code:

<!--BEGIN HYPE WIDGET-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="http://lookbook.nu/look/widget/7625244.js?include=all&size=medium&style=button&align=center"></script><div id="hype_container_7625244">
</div>
<!--END HYPE WIDGET--> 

Ps: impractical use noConflict is because I have to replace all the scripts of my system. It would take me too long to do this.

** Sorry, I don't speak Engish. Google Translate is my best friend. :D

NRKirby
  • 1,584
  • 4
  • 21
  • 38

1 Answers1

1

The big question in this case is how the snippets get into your HTML source. If you load the code dynamically via AJAX and add it with .innerHTML() (or JQuery's .html() method for that matter), you can first filter it with a regex and replace the offending script tag. I'd try somthing like this:

\<script\s+src\=["'][^>]*?jquery[^>]*?\>\<\/script\>\n?

If you use this and replace it with an empty string BEFORE you inject the code into your DOM, than you should be fine.

If you already output the code serverside, e.g. in PHP you could also replace the tag with preg_replace() before echoing it.

The important thing is only to do the clean up before inserting it into the DOM.

P.S.: pattern updated to prevent it from matching another tag that goes before it.

Eric J. Francois
  • 682
  • 1
  • 7
  • 14