-1

I have a function that looks like:

function update(id) {
   location.href = 'contact.html';
   console.log("message"); 
}

I noticed that the message prints out while on the current page then quickly changes to the new page. Every thing I do is done on the current page even though I put the location.href in the beginning of the function. It's pretty frustrating.

I need to work on the new page using the parameters I passed in.

EDIT: ugh I'm beyond frustrated. Can't believe I just spent over 10 hours on a technical assessment for an interview when it was mentioned this was only supposed to take 3-5 hours. Maybe this job isn't for me.

  • If you want to keep the content of the console between navigation changes, in the chrome dev tools, if you right click anywhere in the console, you can select 'Preserve log upon navigation'. – Jonno_FTW Feb 09 '14 at 04:36

2 Answers2

0

You can not control the new page (anything on new page) using javascript code in the current page. Here is an alternative approach:

  1. Load the new page in iframe.
  2. Add a class (say fullDimensions {width:100%; height:100%} ) to iframe element and make iframe cover the entire page.
  3. It will look like that a new page is loaded on your screen but you will stay on the same page.
  4. But you have to respect same origin policy viz iframe should load page from the sme domain.
  5. Then you can access the contentDocument of iframe and play with it.

Hope it helps!!

Community
  • 1
  • 1
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
  • I'm only supposed to use what is given to me which is Javascript. I'm trying to create an address book. Basically each contact needs to have their own page and I'm trying to pass the id through the function. Maybe I'm approaching this the wrong way. How do I create a page for each user? – user3270497 Feb 09 '14 at 04:30
  • @user3270497 Please put your use case in the question so that people can help you with better suggestions. – Sachin Jain Feb 09 '14 at 04:35
0

Put the console.log, or other new actions, on the new page. Once the page location changes, nothing in the first page can impact it.

Miro
  • 5,307
  • 2
  • 39
  • 64