简体   繁体   中英

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.

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.

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