使用原生JavaScript动态更改HTML源代码? [英] Dynamically change the HTML source using native JavaScript?

查看:440
本文介绍了使用原生JavaScript动态更改HTML源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改我的HTML文件。请参阅以获得更好的理解我所做的。



每件事情都可以正常工作,但是当我查看源代码时没有改变。我试图做的改变只反映在我在浏览器上打开的网页上。



是否可以通过任何方式更改实际HTML页面的源代码?



我正在使用IE8和GreaseMonkey4IE在我想要操作的网页上运行我的JavaScript,以防万一您感兴趣。



有类似的问题此处。但我的本地存储中有我的HTML文件。没有服务器端 - 客户端技术。



编辑1


那么我确实设置了Tomcat,但它是都在我的本地机器上。

同样,如果我可以修改DOM,我不能将它另存为一个新的HTML文件,这样我就不必乱用原始源文件。


这就是我们的做法在Firefox中。在IE8中必须有一些方法来实现它。



编辑2

现在,对于没有任何框架的HTML网页可正常工作。但是当我在带有框架的页面上尝试这些时,它不起作用。它肯定会杀死我。
也许这是因为框架访问其他HTML页面。例如:

 < frameset rows =95,*frameborder =NOframespacing =0 border =0marginwidth =0marginheight =0> 
< frame name =titletarget =contentsrc =Strategy%20Details.asp_files / title.htmscrolling =NO>
< frameset cols =168,*>
< frame name =navigationnoresize =noresizewidth =168target =contentsrc =Strategy%20Details.asp_files / navigation.htm>
< frame name =contentnoresize =noresizesrc =策略%20Details.asp_files / home.htm>
< / frameset>
< / frameset>




了解框架如何访问 src 属性。


任何想法???

解决方案您可以使用IE开发工具查看动态更改。



当您查看源代码时,该页面会显示已交付的源代码从服务器没有任何更改后做出。 IE开发者工具(或者Firefox中的Firebug或者Opera中的Dragonfly)可以让你动态地看到变化(并且在变化发生时也会突出变化!)

I was trying to change my HTML files. Please see this to get a better understanding of what I am up to.

Every thing worked fine but as I viewed the source it was not changed. The changes I was trying to make were only reflected on the web-page I had opened on my browser.

Is it by any way possible to change the actual source of the HTML page?

I am using IE8 and GreaseMonkey4IE to run my JavaScript on the web pages I want to manipulate, just in case you are interested.

There is a similar question here. But I have my HTML files at my local storage. No server side - client side technicalities.

EDIT 1

Well I do have setup Tomcat but it is all in my local machine.
Also if I can modify the DOM can't I save it as a new HTML file, this way I won't have to mess with the original source file.

This is how we do it in firefox. There must be some way to do it in IE8.

EDIT 2
Now it is working fine for the HTML pages without any frames. But when I am trying this on pages with frames it is not working.It is going to kill me i am sure. Perhaps this is because frame access other HTML pages. For example :

<frameset rows="95,*" frameborder="NO" framespacing="0" border="0" marginwidth="0"  marginheight="0">
    <frame name="title" target="content" src="Strategy%20Details.asp_files/title.htm"  scrolling="NO">
 <frameset cols="168,*">
   <frame name="navigation" noresize="noresize" width="168" target="content" src="Strategy%20Details.asp_files/navigation.htm">
   <frame name="content" noresize="noresize" src="Strategy%20Details.asp_files/home.htm">
 </frameset>
 </frameset> 



See how the frames are accessing the HTML pages in src attribute.

Any Idea ???

解决方案

You should be able to see the dynamic changes using IE Developer Tools.

When you "View Source" the page shows you the source that was delivered from the server without any changes made afterwards. IE Developer Tools (or Firebug in Firefox, or Dragonfly in Opera) will let you see changes dynamically (and will also highlight changes as they occur!)

这篇关于使用原生JavaScript动态更改HTML源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆