0

I have two HTML files: index.html and Page2.html.
I have a button in index.html page which is called WWW_onclick().
As you see below, this function opens Page2.html and writes "hello".
Problem is this function wipes out the original Page2.html and only writes "hello".

Is there a way to keep the content of the Page2.html and add additional text, image, or ... in it?

function WWW_onclick()
{
   document.location.href = "Page2.html";
   document.write("hello");
}
Juan Leni
  • 6,982
  • 5
  • 55
  • 87
HaNas
  • 25
  • 4
  • Duplicate: http://stackoverflow.com/questions/9280750/how-to-change-content-after-page-is-loaded-js – Quentin May 07 '17 at 18:57

1 Answers1

0

Take a look at document.write.

It will clear your HTML.

You should use innerHTML

Example:

document.getElementById("your-id").innerHTML = "hello";
Edward
  • 2,291
  • 2
  • 19
  • 33
  • I tried this but it only opened the page2 $(document).ready(function(){ $("#btn1").click(function(){ document.location.href = "Page2.html"; document.getElementById("par").innerHTML = "hello"; }); }); – HaNas May 08 '17 at 03:03
  • @HamidNasr Edit your OP and tell us what you have tried. – Edward May 08 '17 at 03:44