T D
T D

Reputation: 125

Replace html text in javascript include

i've got this:

<script type="text/javascript" src="http://xy.com/something.js"></script>

in my php/html file. It includes the whole something.js file. In this file, there are lines like with "document.write..." that are writing some text on my page.

Is it possible to replace a string that is included from this js file in my php document? I can't change the js file (I don't have access to it).

More information:

The .js file looks like this:

...
var msg = '';
msg +='<b>mystring1</b><br/><i>mystring2</i>';
document.write(msg);
...

My php file includes the js file. I wanna change the mystring2 to myteststring in PHP. Is this possible? How? Thanks.

Upvotes: 0

Views: 390

Answers (1)

Alex Jasmin
Alex Jasmin

Reputation: 39496

You can't do this cleanly.

If the .js file is calling document.write() inline and it doesn't access any external variables or functions you really don't have any control over it. You could perhaps redefine document.write() but that's ugly.

I suggest you either maintain your own copy of that .js file or change the document a second time using another script executed from the window.onload event.

Upvotes: 2

Related Questions